akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
using namespace std;
const int N = 110, W = 2e5 + 10, mod = 1e9 + 7; 
long long a[N], b[N], dp[W], ans;
int main(){
    int n, w;
    cin >> n >> w;
    for(int i = 1; i <= n; i++){
        cin >> b[i] >> a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = w; j >= 0; j--){
            if(j >= b[i])dp[j] = max(dp[j], dp[j - b[i]] + a[i]);
            ans = max(ans, dp[j]);
        }
    }
    cout << ans << endl;
}  

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

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<vector<int>> vec(h,vector<int>(w));
  string p;
  int count=1;
  for(int i=0;i<h;i++){
    cin>>p;
    for(int j=0;j<w;j++){
      if(p.at(j)=='#'){
        vec.at(i).at(j)=count;
        count++;
      }
    }
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(vec.at(i).at(j)==0){
        for(int k=j;k>=0;k--){
          if(vec.at(i).at(k)!=0){
            vec.at(i).at(j)=vec.at(i).at(k);
            break;
          }
        }
      }
    }
  }
  
  for(int i=0;i<h;i++){
    if(vec.at(i).at(0)==0){
      for(int j=0;j<w;j++){
        if(vec.at(i).at(j)!=0){
          for(int k=0;k<j;k++){
            vec.at(i).at(k)=vec.at(i).at(j);
          }
          break;
        }
      }
    }
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(vec.at(i).at(j)==0){
        for(int k=i;k>=0;k--){
          if(vec.at(k).at(j)!=0){
            vec.at(i).at(j)=vec.at(k).at(j);
            break;
          }
        }
      }
    }
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(vec.at(i).at(j)==0){
        for(int k=0;k<h;k++){
          if(vec.at(k).at(j)!=0){
            vec.at(i).at(j)=vec.at(k).at(j);
            break;
          }
        }
      }
    }
  }
      
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<vec.at(i).at(j)<<" ";
    }
    cout<<endl;
  }
  
        
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code

int main()
{
	int n, k;
	cin>>n>>k;
	double minn = min(n, k-1);
	double add = max(0, n-k+1);
	double ans = 0.0;
	for(int i=1; i <= minn; i++)
	{
		int z = ceil(log2(((double)k / ((double)i))));
		double p = pow(2, z);
		ans += (1/ p);
	}
	ans += add;
	ans *= 1 / (double)n;
	cout<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 512
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n, k;
char tmp[maxn];
string s;

int read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  scanf("%d", &k);
  return true;
}

void solve() {
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a') {
      continue;
    }
    int need = 'z' - s[i] + 1;
    if (need <= k) {
      s[i] = 'a';
      k -= need;
    }
  }
  s[n - 1] = char('a' + ((s[n - 1] - 'a') + k) % 26);
  printf("%s\n", s.c_str());
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn=10000;

int main(){
    
    string s;
    int ans1=0,ans2=0;
    cin >> s;
    
    char p='0';
    rep(i,s.size()){
        if(s[i]!=p){
            ans1++;
        }
        if(p=='0')p='1';
        else p='0';
    }
    p='1';
    rep(i,s.size()){
        if(s[i]!=p){
            ans2++;
        }
        if(p=='0')p='1';
        else p='0';
    }
    
    cout << min(ans1,ans2)<<endl;
    
    return 0;
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    int n;
    cin >> n;
    vector<lli> a(n);
    for(auto& i : a) cin >> i;
    lli xorv = 0;
    for(auto i : a) xorv ^= i;
    if(xorv == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1024
#![allow(unused_imports)]

#[macro_use]
mod _input {
    use std::fmt;
    use std::io::{self, Read};
    use std::str::{self, FromStr};

    macro_rules! input {
        ($($name:ident : $t:tt),*,) => {
            input!($($name: $t),*)
        };
        ($($name:ident : $t:tt),*) => {
            let mut _scanned = ::_input::Scanned::new(::std::io::stdin(), 1024);
            $(
                let $name = _read_value!(_scanned, $t);
            )*
        };
    }

    macro_rules! _read_value {
        ($scanned:expr, ($($t:tt),*)) => {
            ($(_read_value!($scanned, $t)),*)
        };
        ($scanned:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| _read_value!($scanned, $t)).collect::<Vec<_>>()
        };
        ($scanned:expr, _bytes) => {
            _read_value!($scanned, String).into_bytes()
        };
        ($scanned:expr, _1based) => {
            _read_value!($scanned, usize) - 1
        };
        ($scanned:expr, $t:ty) => {
            $scanned.next::<$t>()
        };
    }

    #[derive(Default)]
    pub struct Scanned {
        buf: Vec<u8>,
        pos: usize,
    }

    impl Scanned {
        pub fn new<R: Read>(mut input: R, estimated: usize) -> Self {
            let mut buf_ = Vec::with_capacity(estimated);
            let _ = io::copy(&mut input, &mut buf_).unwrap();
            if buf_.last() != Some(&b'\n') {
                buf_.push(b'\n');
            }
            debug_assert!(str::from_utf8(&buf_).is_ok());
            debug_assert!(buf_.iter().all(|&c| u32::from(c) <= 0x7F));
            Scanned { buf: buf_, pos: 0 }
        }

        #[inline]
        pub fn next<T: FromStr>(&mut self) -> T
        where
            T::Err: fmt::Debug,
        {
            let mut start = None;
            loop {
                match (self.buf[self.pos], start.is_some()) {
                    (b' ', true) | (b'\n', true) => break,
                    (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                    (_, false) => start = Some(self.pos),
                }
            }
            let target = &self.buf[start.unwrap()..self.pos];
            unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
        }
    }
}

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Stderr, StderrLock, Stdout, StdoutLock, Write};
use std::num::{ParseFloatError, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, mem, thread, u16, u32, u64, u8};

fn main() {
    input! {
        n: usize,
        ls: [u32; n],
    }
    let m = ls.iter().cloned().max().unwrap();
    let s = ls.iter().cloned().sum::<u32>();
    println!("{}", if 2 * m < s { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
#define INF 1000000000
#define MOD 1
#define SIZE 100001
using namespace std;

map<ll,ll>af,bf;
ll a,b;

void factor(ll x){
	map<ll,ll>temp;
	ll x1=x;
	while(true){
	  if(x==1){break;}
	  for (ll i=2; i<=x1; i++){
		  ll counter=0;
		  if(x%i==0){
			  while(true){
				  if(x%i!=0){break;}
				  x/=i;
				  counter++;
			  }
			  //cout<<i<<" "<<counter<<endl;
			  temp[i]=counter;
		  }
	  }
	}
  x1==a?af=temp:bf=temp;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin>>a>>b;
  factor(a);factor(b);
  map<ll,ll>:: iterator it;
  map<ll,bool>taken;
  map<ll,ll>nums;
  for (it=af.begin(); it!=af.end(); it++){
	  nums[it->first]=it->second;
	  //cout<<it->first<<" "<<it->second<<"\n";
  }
  for (it=bf.begin(); it!=bf.end(); it++){
	  nums[it->first]=max(nums[it->first],it->second);
	  //cout<<it->first<<" "<<it->second<<"\n";
  }
  ll ans=1;
  for (it=nums.begin(); it!=nums.end(); it++){
	  ans*=pow(it->first,it->second);
	  //cout<<it->first<<" "<<it->second<<"\n";
  }
  cout<<ans;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr ll MOD = 1'000'000'007;
std::string S;

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

    std::cin >> S;

    ll n = 1, an = 0, abn = 0;
    ll cnt = 0;

    for(char &c : S){
        if(c == 'A'){
            an = (an + n) % MOD;
        }else if(c == 'B'){
            abn = (abn + an) % MOD;
        }else if(c == 'C'){
            cnt = (cnt + abn) % MOD;
        }else{
            cnt = (cnt * 3 % MOD + abn) % MOD;
            abn = (abn * 3 % MOD + an) % MOD;
            an = (an * 3 % MOD + n) % MOD;
            n = n * 3 % MOD;
        }
    }

    std::cout << cnt << std::endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int bubbleSort(int A[], int N) {
	int flag = 1, count = 0;
	while (flag)
	{
		flag = 0;
		for (int j = N - 1; j > 0; j--)
		{
			if (A[j] < A[j - 1]) {
				int tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				flag = 1;
				count++;
			}
		}
	}

	for (int k = 0; k < N; k++)
	{
		if (k > 0) printf(" ");
		printf("%d", A[k]);
	}
	printf("\n%d\n", count);

	return 0;
}


int main() {
	int N, i, j;
	int A[100];

	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &A[i]);

	bubbleSort(A, N);

	return 0;
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	vector <vector <int>> v (n,vector <int> (2,0));
	for(int i=0;i<n;++i){
		int d1,d2;
		cin>>d1>>d2;
		v[i][0] = d1;
		v[i][1] = d2;
	}
	bool ok = true;
	for(int i=0;i<=n-3;++i){
		ok = true;
		for(int j=0;j<3;++j){
			if(v[i+j][0]!=v[i+j][1]){
				ok = false;
				break;
			}
		}
		if(ok) break;
	}
	if(ok) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3628
d, gl = map(int, input().split())
p = []
g = []
for i in range(d):
  P,G = map(int, input().split())
  p.append(P)
  g.append(G)
ans = sum(p)
for i in range(1<<d):
  tmp = 0
  c = 0
  b = [0 for i in range(d)]
  for j in range(d):
    if i&(1<<j):
      tmp += g[j] + (j+1)*p[j]*100
      c += p[j]
      b[j] = 1
  s = d-1
  while tmp < gl and s >= 0:
    if b[s] == 1:
      s -= 1
    else:
      for k in range(p[s]):
        tmp += 100*(s+1)
        c += 1
        if tmp >= gl:
          break
      s -= 1
  ans = min(ans,c)
print (ans)

Measured memory_bytes: 9172
d, g = gets.split.map(&:to_i)
qs = []
d.times{|i|
  p, c = gets.split.map(&:to_i)

  qs << {
    :p => p,
    :c => c,
    :c_score => (i + 1) * 100 * p + c,
    :r_score => (i + 1) * 100 * p
  }
}

solve_min = nil
for p in 0..((2 ** d) - 1)
  rough_solve_index = nil
  solved = 0
  score = 0
  for i in 0...d
    index = d - i - 1
    if ((p >> index) & 1) == 1
      solved += qs[index][:p]
      score += qs[index][:p] * (100 * (index + 1))
      score += qs[index][:c]
    else
      rough_solve_index = index if rough_solve_index == nil
    end
  end
  if score < g
    less = g - score
    next if rough_solve_index == nil
    next if qs[rough_solve_index][:r_score] < less
    s = less / ((rough_solve_index + 1) * 100)
    s += 1 if less % ((rough_solve_index + 1) * 100) != 0
    solved += s
  end
  solve_min = solved if solve_min == nil
  solve_min = [solved, solve_min].min
end

puts solve_min


Measured memory_bytes: 1788
# -*- coding: utf-8 -*-

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

H, W = map(int, input().split())
a = []

a.append('#' * W)

for i in range(H):
    a.append(input())
    
a.append('#' * W)

for i in range(len(a)):
    a[i] = '#' + a[i] + '#'
    print(a[i])




Measured memory_bytes: 4680
#include<stdio.h>
#include<stdlib.h>
int partition(int *,int,int);

int main(){
  int i,n,p,*a;
  scanf("%d",&n);
  a=malloc(sizeof(int)*n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  p=partition(a,0,n-1);
  for(i=0;i<n;i++){
    if(i==n-1)printf("%d\n",a[i]);
    else if(i==p)printf("[%d] ",a[i]);
    else printf("%d ",a[i]);
  }
  free(a);
  return 0;
}

int partition(int *A,int p,int r){
  int x,i,j,box;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(x>=A[j]){
      i++;
      box=A[i];
      A[i]=A[j];
      A[j]=box;
    }
  }
  i++;
    box=A[r];
    A[r]=A[i];
    A[i]=box;
    return i;
}



Measured memory_bytes: 2048
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    let v = arg[1].split(" ").map(n=>parseInt(n)).sort((a,b)=>a-b);
    
    while(v.length !== 1) {
        let x = v[0];
        let y = v[1];
        
        let temp = (x + y) / 2;
        
        v.shift();
        v.shift();
        
        v.unshift(temp);
        
        v.sort((a,b)=>a-b);
    }
    
    console.log(v[0]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}

const int INF = 1001001001;

bool che(string s) {
	if (s[0] != 'A')return false;
	int c = 0;
	for (int i = 2; i < s.size()-1; i++) {
		if (s[i] == 'C')c++;
	}
	if (c != 1)return false;
	int up = 0;
	rep(i, s.size()) {
		if (s[i] >= 'A' && s[i] <= 'Z')up++;
	}
	if (up != 2)return false;
	return true;
}
int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	cout << (c - a) * 60 + (d - b) - e;
	return 0;
}













Measured memory_bytes: 3632
const val mod = 2019

fun main() {
	val t = readLine()!!
	val a = IntArray(mod) {0}
	a[0] = 1

	var m = 0
	var d = 1

	var r = 0L

	for(c in t.reversed().map {it-'0'}) {
		m = (m+c*d)%mod
		r += a[m]++
		d = d*10%mod
	}
	println(r)
}


Measured memory_bytes: 42172
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 
    int n;
    cin >> n;
 
    if(n == 1){
        cout << "Hello World" << endl;
    }else{
        int a, b;
        cin >> a >> b;
        cout << a+b << endl;
    }
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxx = 10000;
int a[maxx]; 
int read(){int k;cin>>k;return k;}
int main(){	
	int n;
	n=read();
	for(int i=1;i<=2*n;i++)a[i]=read();
	sort(a+1,a+1+2*n);
	long long ans=0;
	for(int i=1;i<=2*n;i+=2)ans+=a[i];
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define VI vector<int>

#define rep(i,a) for(int i=0;i<(a);i++)
#define all(i) i.begin(),i.end()
#define INF 1000000000


using namespace std;
int n,p;

int check(int mem[100]){
	int count=0;
	int ret;
	rep(i,n){
		if(mem[i]!=0){
			count++;
			ret=i;
		}
	}
	if(count==1)return ret;
	return -1;
}

int main(){
	while(1){
		int mem[100]={};
		cin>>n>>p;
		if(n==0 && p==0)break;
		int box=p;
		int count=0;
		while(1){
			if(box==0){
//				cout<<"1"<<endl;
				box+=mem[count%(n)];
				mem[count%(n)]=0;
			}
			else{
//				cout<<"2"<<endl;
				mem[count%(n)]++;
				box--;
				int ret;
				if( (ret=check(mem))!=-1 && box==0){
					cout<<ret<<endl;
					break;
				}
			}
			count++;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

t = list(input())
d = defaultdict(int)

k = 0
for i in t:
    d[i] += 1
for i in d:
    if d[i] == 2:
        k += 1
if k == 2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 8004
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = getLong(sc);
		List<Long> monsters = new ArrayList<>();
		monsters.add(h);

		long count = calcAttack(h, 1, 0);

		System.out.println(count);
	}

	private static long calcAttack(long hp, long monsters, long count) {
		count += monsters;
		if (hp == 1) {
			return count;
		} else {
			return calcAttack(hp / 2, monsters * 2, count);
		}

	}

	private static boolean isEqual(Integer[] perm, int[] target) {
		for (int i = 0; i < perm.length; i++) {

			if (perm[i].intValue() != target[i]) {

				return false;
			}
		}
		return true;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 23764
# from math import gcd
from fractions import gcd
from functools import reduce


def lcm(x,y):   
    return x*y//gcd(x,y)

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

l=reduce(lcm,A)
    
ans=0
for i in range(N):
    ans+=l//A[i]

print(ans%(10**9+7))

Measured memory_bytes: 6100
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static String S, T;
    static int result = 0;

    public static void main(String[] args) throws Exception {
        S = br.readLine();
        T = br.readLine();
        
        for(int i = 0; i < S.length(); i++){
           if(S.charAt(i) != T.charAt(i)){
                result++;
           }
        }
        System.out.println(result);
    }

}

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

int main() {
  string N;
  cin >> N;
  if (N[0] == N[1] && N[0] == N[2]) cout << "Yes" << endl;
  else if (N[1] == N[2] && N[1] == N[3]) cout << "Yes" << endl;
  else if (N[0] == N[1] && N[0] == N[2] && N[0] == N[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>

using namespace std;

int main() {
	int n, x;
	vector<int> furui(1000000+1, 0);
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i <= 1000000; i++) {
		if (furui[i] == 0) {
			for (int j = 2; i*j <= 1000000; j++) {
				furui[i*j] = 1;
			}
		}
	}
	while (cin >> n >> x) {
		if (n == 0 && x == 0) {
			break;
		}
		vector<int> en;
		priority_queue<int, vector<int>, greater<int> > pq;
		vector<int> dp(x+1, 0);
		for (int i = 0; i < n; i++) {
			int k;
			cin >> k;
			if (k > x || k == 0) {
				continue;
			}
			dp[k] = 1;
			pq.push(k);
		}
		if (!pq.empty()) {
			int p = pq.top();
			pq.pop();
			en.push_back(p);
		}
		while (!pq.empty()) {
			int k = pq.top();
			pq.pop();
			bool hantei2 = true;
			for (int i = 0; i < en.size(); i++) {
				if (k % en[i] == 0) {
					hantei2 = false;
					break;
				}
			}
			if (hantei2) {
				en.push_back(k);
			}
		}
		for (int i = 0; i < en.size(); i++) {
			for (int j = 0; j <= x; j++) {
				if (j < en[i]) {
				} else {
					dp[j] = max(dp[j], dp[j-en[i]]);
				}
			}
		}
		bool hantei = true;
		for (int i = x; i >= 0; i--) {
			if (dp[i] > 0 && furui[i] == 0) {
				cout << i << endl;
				hantei = false;
				break;
			}
		}
		if (hantei) {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 12084
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

var (
	ans  []int
	tree [][]int
)

func main() {

	var S, T string
	var count int

	fmt.Scan(&S)
	fmt.Scan(&T)

	for i, runeS := range S {
		for j, runeT := range T {
			if i == j && runeS == runeT {
				count++
			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "

using namespace std;
///check n=1;
///check corner case;

int main()
{
    string a,b,c;
    cin>>a;
    b="AAA";
    c="BBB";
    if(a==b || a==c)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
return 0;
}


Measured memory_bytes: 256
max2 = lambda x,y: x if x > y else y

def solve(N,A,B):
    if A+B > N+1:
        return None
    if A*B < N:
        return None


    res = [-1]*N
    rem = A

    i = 0
    while i+B+rem-1 < N:
        rem -= 1
        o = i+B
        for k in range(B):
            res[i+k] = o-k-1
        i += B

    p = N-i-rem+1
    for k in range(p):
        res[i+k] = i+p-k-1
    i += p
    rem -= 1
    for k in range(i,N):
        res[k] = k
    return res






from itertools import permutations
def naive(N,A,B):

    for p in permutations(range(N)):
        dp = [1]*N
        for i in range(N):
            for j in range(i):
                if p[j] < p[i]:
                    dp[i] = max2(dp[i],dp[j]+1)

        a = max(dp)

        dp = [1]*N
        for i in range(N):
            for j in range(i):
                if p[j] > p[i]:
                    dp[i] = max2(dp[i],dp[j]+1)

        b = max(dp)

        if a == A and b == B:
            return p
    return None

if __name__ == '__main__':
    N,A,B = map(int,input().split())
    res = solve(N,A,B)
    if res is None:
        print(-1)
    else:
        print(*(v+1 for v in res))

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

using namespace std;

#define ll long long
#define mod 1000000007

map<int,set<int> > row;
map<int,set<int> > column;
void solve(){
	std::srand ( unsigned ( std::time(0) ) );
	int n,m,q;
	cin>>n>>m;
	int x,y;
	cin>>q;
	for(int i = 0;i<q;i++){
		cin>>x>>y;
		if(row.find(x) != row.end())row[x].insert(y);
		else{
			set<int> st;
			row.insert({x,st});
			row[x].insert(y);
		}
		if(column.find(y) != column.end())column[y].insert(x);
		else{
			set<int> st;
			column.insert({y,st});
			column[y].insert(x);
		}
	}
	int mxr = 0;
	int mxc = 0;
	for(auto it:row){
		mxr = max(mxr,(int)it.second.size());
	}
	for(auto it:column){
		mxc = max(mxc,(int)it.second.size());
	}
	vector<int> rowMax,maxColumn;
	for(auto it:row){
		if(it.second.size() == mxr){
			rowMax.push_back(it.first);
		}
	}
	int ans = 0;
	for(auto it:column){
		if(it.second.size() == mxc){
			maxColumn.push_back(it.first);
		}
	}
	random_shuffle(rowMax.begin(),rowMax.end());
	for(int i = 0;i<rowMax.size();i++){
		for(int j = 0;j<maxColumn.size();j++){
			if(row[rowMax[i]].find(maxColumn[j]) == row[rowMax[i]].end()){
				ans = mxc + mxr;
				break;
			}
		}
		if(ans != 0)break;
	}
	if(ans == 0){
		cout<<mxc+mxr -1;
	}else{
		cout<<ans;
	}
}

int main(){
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 91844
#include <bits/stdc++.h>
#define W 0
#define B 1
#define G 2
#define rep(i,a) for(i=1;i<=a;i++)
using namespace std;

vector <vector<int> > A;
vector <int> c;
vector <int> d;
vector <int> f;
vector <int> k;

int n,u,t;

void visit(int r) {
    int i;
    c[r] = G;
    d[r] = ++t;
    rep(i,k[r]){
        if(c[A[r][i]] == W) visit(A[r][i]);
    }
    c[r] = B;
    f[r] = ++t;
}

void dfs(void){
    int i;
    rep(i,n) 
        c[i] = W;
    t = 0;
    rep(i,n){
        if(c[i] == W) visit(i);
    }
}

int main(void){
    int i,j;
    cin >> n;
    c.resize(n+1);
    d.resize(n+1);
    f.resize(n+1);
    k.resize(n+1);
    A.resize(n+1);
    rep(i,n) A[i].resize(n+1);
    rep(i,n){
        cin >> u >> k[i];
        rep(j,k[i]){
            cin >> A[i][j];
        }
    }
    dfs();
    rep(i,n){
        cout << i << " " <<d[i] << " "<< f[i] << endl;
    }
    return 0;
}

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

#define ll long long
#define endl '\n'
#ifndef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
#define getchar getchar_unlocked
#endif

template <typename Func>
inline void loop(int e, Func&& f) {
    for (int i = 0; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename Func>
inline void loop(int s, int e, Func&& f) {
    for (int i = s; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename T>
inline void scanpn(T& num) {
    int c;
    num = 0;
    c = getchar();
    // bool negative = false;
    // if (c == '-') {
    // 	negative = true;
    // 	c = getchar();
    // }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    // if (negative)
    //     number = -number;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n;
    vector<int> sub(n, 0);
    for (int i = 0; i < n - 1; i++) {
        cin >> t;
        sub[t - 1]++;
    }
    for (auto& m : sub) {
        cout << m << endl;
    }
    return 0;
}


Measured memory_bytes: 3972
N, W = gets.split.map(&:to_i)
WV = N.times.map{gets.split.map(&:to_i)}.sort_by{|a|[a[0], a[1]]}
#N = 100
#W = 10 ** 9
#WV = N.times.map{[rand(1..W-1), rand(1..10**3)]}.sort_by{|a|[a[0], a[1]]}

dp = Hash.new(Float::INFINITY)
dp[0] = 0
que = [0]

WV.each do |w, v|
  dp_dup = dp.dup
  dp_dup.each do |dp_v, dp_w|
    nw, nv = w + dp_w, v + dp_v
    next if nw > W
    
    if dp[nv] > nw
      dp[nv] = nw
    end
  end
end
p dp.keys.max


Measured memory_bytes: 79944
# 半分全列挙
from bisect import bisect, bisect_left
N, K, L, R = map(int, input().split())
*A, = map(int, input().split())


def enum(A):
    n = len(A)
    ret = [[] for _ in [0]*(N+1)]
    for i in range(1 << n):
        sun = 0
        cnt = 0
        for j, a in enumerate(A):
            if i >> j & 1:
                sun += a
                cnt += 1
        ret[cnt].append(sun)

    return [sorted(r) for r in ret]


S1 = enum(A[:N//2])
S2 = enum(A[N//2:])

ans = 0
for k, _S1 in enumerate(S1):
    if k == K:
        l = bisect_left(_S1, L)
        r = bisect(_S1, R)
        ans += r-l
        continue
    if K-k < 0:
        break

    _S2 = S2[K-k]
    for a in _S1:
        l = bisect_left(_S2, L-a)
        r = bisect(_S2, R-a)
        ans += r-l

print(ans)



Measured memory_bytes: 116168
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_ss = Array.init h @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let s = String.make (w + 2) '#'
let _ =
  print_endline s;
  Array.iter (Printf.printf "#%s#\n") a_ss;
  print_endline s

Measured memory_bytes: 512
import heapq

def dijkstra(edges, s):
    hq = []
    d = [-1] * n
    d[s] = 0
    heapq.heappush(hq, (0, s))
    while hq:
        d1, p = heapq.heappop(hq)
        for i in edges[p]:
            if d[i] == -1 or d[i] > d1 + 1:
                d[i] = d1 + 1
                heapq.heappush(hq, (d1+1, i))
    return d

n,x,y = map(int,input().split())
edges = [[] for _ in range(n)]

for i in range(n):
    if i == 0:
        edges[i].append(i+1)
    elif i == n-1:
        edges[i].append(i-1)
    else:
        edges[i].append(i-1)
        edges[i].append(i+1)
edges[x-1].append(y-1)
edges[y-1].append(x-1)

ans = [0] * (n-1)

for i in range(n):
    d = dijkstra(edges, i)
    for j in d:
        if j != 0:
            ans[j-1] += 1

for i in ans:
    print(i//2)


Measured memory_bytes: 70748
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    string a;
    int r[6][2]={{1,2},{-1,3},{1,-1},{4,5},{5,2},{2,1}};
    while(cin >> a,a != "#"){
        int now = 0;
        bool flg = 0;
        for(int i = 0; i < a.size(); i++){
            now = r[now][a[i]-'0'];
            if(now == -1){
                flg = 1;
                break;
            }
        }
        if(flg)cout << "No" << endl;
        else cout << (now == 5?"Yes":"No") << endl;
    }
    return 0;
}

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

typedef long long ll;

ll p = 1e9+7;

int main(){
    int N, M;
    cin >> N >> M;
    
    ll ans=1;
    if(abs(N-M)>=2) cout << 0 << endl;
    else if((N+M)%2==0){
        for(int i=N; i>0; i--){
            ans *= N--;
            ans = ans%p;
            ans *= M--;
            ans = ans%p;
        }
        cout << (ans+ans)%p << endl;
    }
    else {
        for(int i=max(N,M); i>0; i--){
            if(N>0) ans *= N--;
            ans = ans%p;
            if(M>0) ans *= M--;
            ans = ans%p;
        }
        cout << ans%p << endl;
    }
}


Measured memory_bytes: 256
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=-1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]
 
def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))
 
def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))
 
def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD
 
    return (num*(pow(den,MOD-2,MOD)))%MOD
 
def flush():
    return sys.stdout.flush()




'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
sieve()



def fun(x,k):
    while x>1:
        d[spf[x]].add(k)
        x//=spf[x]

n = int(input())
a = arrIN()
d = defaultdict(set)

for i in range(n):
    fun(a[i],i)

g = a[0]

for i in range(1,n):
    g = math.gcd(g,a[i])


for i in d.keys():
    if i>1 and len(d[i])>1:
        if g!=1:
            print('not coprime')
        else:
            print('setwise coprime')
        break
else:
    print('pairwise coprime')


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

#define maxn 100000
#define maxm 200000

int n,m;
int a[maxm+5];
int c[maxm+5];

void readin(){
    scanf("%d",&n);
    m=n*2-1;
    for(int i=1;i<=m;i++) {
        scanf("%d",&a[i]);
    }
}

void Turn(int x) {
    for(int i=1;i<=m;i++){
        c[i]=(a[i]>=x);
    }
}

bool judge(int x){
    Turn(x);
    int p1=0,p2=m+1;
    for(int i=n;i>=2;i--){
        if(c[i]==c[i-1]){
            p1=i;
            break;
        }
    }
    for(int i=n;i<m;i++) {
        if(c[i]==c[i+1]) {
            p2=i;
            break;
        }
    }
    if(p1==0&&p2==m+1) return c[1];
    if(n-p1>p2-n) return c[p2];
    else return c[p1]; 
}

int binsearch() {
    int l=0,r=m;
    while(l+1<r) {
        int mid=l+(r-l)/2;
        if(judge(mid)) l=mid;
        else r=mid;
    }
    if(judge(l+1)) return l+1;
    if(!judge(l)) return l-1;
    else return l;
}

int main(){
    readin();
    int ans=binsearch();
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc126_d


class Graph():

    def __init__(self):
        self.adjacency_dict = {}
        self.weight = []
    
    def add_vertex(self, v):
        self.adjacency_dict[v] = []
        self.weight.append([])

    def add_edge(self, v1, v2, w):
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)
        self.weight[v1].append(w)
        self.weight[v2].append(w)

    def get_vertexes(self):
        return self.adjacency_dict.keys()

    def get_edges(self, v):
        return self.adjacency_dict[v], self.weight[v]

    def print_graph(self):
        print(self.adjacency_dict)

n = int(input())

res = []
g = Graph()
for i in range(n):
    res.append(-1)
    g.add_vertex(i)

for i in range(n-1):
    u, v, w = map(int, input().strip().split())
    g.add_edge(u-1, v-1, w % 2)

q = []
res[0] = 0
q.append(0)
while(len(q) > 0):
    v = q.pop()
    u_l, w_l = g.get_edges(v)
    for u, w in zip(u_l, w_l):
        if res[u] != -1:
            continue
        res[u] = (res[v] + w) % 2
        q.append(u)

for i in range(n):
    print(res[i])


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

#define ll long long
#define MAX_W 100002
#define MAX_V 1000000002

ll w[101];
ll v[101];
ll mem[101][MAX_W];
//int N;

ll knapsack(ll n, ll W)
{
    if(n == 0 || W == 0)
    {
        return 0;
    }

    if(mem[n][W] != -1)
    {
      return mem[n][W];
    }

    if(w[n-1]<=W)
    {
        mem[n][W] = max(v[n-1]+knapsack(n-1,W-w[n-1]),knapsack(n-1,W));
    }
    else if(w[n-1]>W)
    {
       mem[n][W] = knapsack(n-1,W);
    }
    return mem[n][W];
}



int main()
{
  //OJ;
  ll W, N;
  cin>>N>>W;
  for(ll i = 0; i < N; i++)
  {
      cin>>w[i]>>v[i];
  }

  memset(mem,-1,sizeof(mem));
 // cout<<fn(0,W)<<endl;
  cout<<knapsack(N,W)<<endl;

   return 0;
}


Measured memory_bytes: 82520
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int[] a = new int[N+1];
	    int count = 0;
	    for(int i = 1; i <= N; i++) {
	        int s = sc.nextInt();
	        a[s] = i;
	    }
	    for(int j = 1; j <= N; j++) {
	        System.out.print(a[j]);
	        if(j < N) {
	            System.out.print(" ");
	        }else {
	            System.out.println("");
	        }
	    }
	}
}

Measured memory_bytes: 63236
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	string S, T, U;
	int A, B;
	cin >> S >> T >> A >> B >> U;
	if(S == U)A--;
	else B--;
	cout << A << " " << B << endl;

	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  int a, b;
  cin >> a >> b;
  cout << max(max(a+b, a-b), a*b) << endl;
}

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


Measured memory_bytes: 892
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
x,k,d = gets.chomp.split.map(&:to_i)

if x < 0
  x = x.abs
end

if x - k * d > 0
  puts x - k * d
else
  r = x % d
  l = r - d
  nokori_k = k - x / d
  # p [l, r, nokori_k]
  if nokori_k.even?
    puts r.abs
  else
    puts l.abs
  end
end

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

using namespace std;
int main(){
  int h,m;
  string str;
  
  while(cin >> str && str!="-"){
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> h;
      string left = str.substr(0, h);// abc 
      string right = str.substr(h);
      str =right +left;
    }
    cout << str << endl;
  }
      
  return 0;
}

Measured memory_bytes: 1216
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    string s;
    cin>>s;
    int n=s.len;
    int x1=0;
    while(s[x1]!='A') x1++;
    int x2=n-1;
    while(s[x2]!='Z') x2--;
    pr(x2-x1+1);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3732
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

bool match(char x, char y)
{
  return (x != '?' && y != '?') ? x == y : true;
}

void precalc(const std::string& x, const std::string y, std::vector<bool>& memo)
{
  for(size_t i = 0; i < x.size(); ++i)
  {
    for(size_t j = 0; j < y.size() && j + i < x.size(); ++j)
    {
      if(!match(x[j + i], y[j]))
      {
        memo[i] = false;
        break;
      }
    }
  }
}

size_t solve(const std::string& a, const std::string& b, const std::string& c,
             const std::vector<bool>& ab, const std::vector<bool>& bc, const std::vector<bool>& ac)
{
  size_t ans = a.size() + b.size() + c.size();
  for(size_t i = 0; i <= a.size(); ++i)
  {
    for(size_t j = i; j <= std::max(a.size(), b.size() + i); ++j)
    {
      if(ab[i] && ac[j] && bc[j - i])
      {
        ans = std::min(ans, std::max(a.size(), std::max(b.size() + i, c.size() + j)));
      }
    }
  }
  return ans;
}

int main()
{
  std::string a,b,c;
  std::cin >> a >> b >> c;
  size_t n = a.size() + b.size() + c.size() + 1;
  std::vector<bool> ab(n,true),ba(n,true),ac(n,true),ca(n,true),bc(n,true),cb(n,true);
  precalc(a,b,ab);precalc(b,a,ba);precalc(a,c,ac);precalc(c,a,ca);precalc(b,c,bc);precalc(c,b,cb);
  size_t ans =        solve(a,b,c,ab,bc,ac);
  ans = std::min(ans, solve(b,a,c,ba,ac,bc));
  ans = std::min(ans, solve(a,c,b,ac,cb,ab));
  ans = std::min(ans, solve(c,a,b,ca,ab,cb));
  ans = std::min(ans, solve(b,c,a,bc,ca,ba));
  ans = std::min(ans, solve(c,b,a,cb,ba,ca));
  std::cout << ans << std::endl;
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i =0;i < N;i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int count = 0;
  for(int j = 0;j < N - 1;j++) {
    count += vec.at(j);
  }
  if(count > vec.at(N - 1)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int N, K;
int x[100000];

int main(void){
	cin >> N >> K;
	for(int i = 0; i < N; i++) cin >> x[i];

	int res = INF;
	for(int i = 0; i <= N - K; i++){
		if(x[i + K - 1] <= 0) res = min(res, abs(x[i]));
		else if(0 <= x[i]) res = min(res, x[i + K - 1]);
		else res = min(res, abs(x[i]) + x[i + K - 1] + min(abs(x[i]), x[i + K - 1]));
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
ll dp[5009];
  ll a[5000];
int main()
{
  ll n;ll ans=0;
  multiset<ll>s;cin>>n;
  for(int i=0;i<n;i++){
      ll x;cin>>x;
      if(s.size()==0){
          s.insert(x);
          ans++;
          }
          else
          {
              auto z=s.begin();
              if(*z>=x){
                  s.insert(x);ans++
;              }else{
              auto it=s.lower_bound(x);it--;
              s.erase(s.find(*it));
               s.insert(x);
}
    
}
  }cout<<ans;

}

Measured memory_bytes: 8192
#include <iostream>
#include <cmath>

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

int main() {
  int N , D , x , y, sum;
  cin >> N >> D ;
  sum = 0;
  for (int i = 0; i < N; i++) {
  	cin >> x >> y;
    if ( ( pow(x, 2) + pow(y, 2) ) <= pow ( D , 2 ) ){
      sum = sum + 1;
    }
    
	}
  cout << sum << endl;
  
}

Measured memory_bytes: 3568