akhauriyash/Code-Regression huggingface dataset:
/***************************************************
 * Problem Name : C - Slimes.cpp
 * Problem Link : https://atcoder.jp/contests/abc143/tasks/abc143_c
 * OJ           : atCoder
 * Verdict      : Trying
 * Date         : 2019-11-23
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    __FastIO;
    //~ cout << setprecision (10);
    //~ cout << fixed;
    int n;
    cin >> n;
    string str;
    cin >> str;
    int cnt = 1;

    for (int i = 1; i < n; i++) {
        if (str[i - 1] != str[i]) cnt++;
    }

    cout << cnt << "\n";
    return 0;
}


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

/* 平面幾何の基本要素 */
 
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS )
 
class Point { // 点を表すクラス
public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }
  
  double abs() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  
  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  
  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

typedef Point Vector; // ベクトルを表す構造体

struct Segment { // 線分を表す構造体
  Point p1,p2;
};

typedef Segment Line; // 直線を表す構造体

class Circle { // 円を表すクラス
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0): c(c),r(r) {}
};
typedef vector < Point > Polygon; // 多角形

double dot(Vector a, Vector b) {
  return a.x * b.x + a.y * b.y;
}
 
double cross(Vector a, Vector b) {
  return a.x * b.y - a.y * b.x;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
 
int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1 - p0;
  Vector b = p2 - p0;
 
  if( cross(a,b) > EPS ) return COUNTER_CLOCKWISE;
  if( cross(a,b) < -EPS ) return CLOCKWISE;
  if( dot(a,b) < -EPS ) return ONLINE_BACK;
  if( a.norm() < b.norm() ) return ONLINE_FRONT;
 
  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return ( ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 && 
	   ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s2.p1,s1.p2,s2.p2);
}

int contains(Polygon g,Point p){
  int n = g.size();
  bool x = false;
  for(int i=0;i<n;i++){
    Point a = g[i] - p, b = g[(i+1)%n] - p;
    if(abs(cross(a,b)) < EPS && dot(a,b) < EPS) return 0;
    if(a.y > b.y) swap(a,b);
    if(a.y < EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
  }
  return (x ? 1 : 0);
}

int main(){
  Point p1,p2,p3,p4;
  char o;
  while(cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> p4.x >> p4.y){
    Polygon g;
    g.push_back(p1);
    g.push_back(p2);
    g.push_back(p3);
    if(contains(g,p4)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1220
#include <stdio.h>
int main(void)
{
	char hougaku[1000];
	int xnf=0,xsf=0,yef=0,ywf=0;
  	int i; 
	scanf("%s",hougaku);
 	for(i=0;hougaku[i]!='\0';i++){
		if(hougaku[i]=='N'){
			xnf=1;
		}
		if(hougaku[i]=='E'){
			yef=1;
		}
		if(hougaku[i]=='W'){
			ywf=1;
		}
 		if(hougaku[i]=='S'){
			xsf=1;
		}
		 
 	}
	if(xnf==xsf&&ywf==yef)	printf("Yes\n");
	else		printf("No\n");
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Pencils
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0641

"""
import sys


def solve(N, A, B, C, D):
    q1, r1 = divmod(N, A)
    ans1 = B * (q1 + (r1 > 0))
    q2, r2 = divmod(N, C)
    ans2 = D * (q2 + (r2 > 0))
    return min(ans1, ans2)


def main(args):
    N, A, B, C, D = map(int, input().split())
    ans = solve(N, A, B, C, D)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



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

int main()
{
	char a;
	cin >> a;
	if(a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o'){
		cout << "vowel" << endl;
	}else{
		cout << "consonant" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#include<iomanip>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int n,maxi=-1,maxs=0;
	cin>>n;
	lol(i,n){
		int a,b;cin>>a>>b;
		if(maxi<a){
			maxi=a;
			maxs=b;
		}
	}
	cout<<maxi+maxs<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll X;
	ll tmp = 100, ans = 0;
	cin >> X;
	while(tmp < X){
		tmp += tmp / 100;
		ans++;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(std::string S){
  cout << (S == "ABC" ? "ARC" : "ABC") << endl;
}

int main(){
    std::string S;
	std::cin >> S;
    solve(S);
}


Measured memory_bytes: 3520
n,k=map(int,input().split())

b=1
S=0
a=0
m=0
for i in range(1,n+1):
    b=i
    for j in range(0,100000):
        if b>=k:
            m=j
            break
        else:
            b=b*2
            continue
    

    S=S+(1/(n*2**(m)))

print(S)

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000

string S;
ll ans = 0;

// i 番目の数字を見ている
// 今までの合計が base
// まだ足してないけど、保持しているのが cur
ll dfs(ll i, ll base, ll cur) {
    ll num = S[i] - '0';
    cur = cur * 10 + num;
    if(i >= S.length()-1) {
        ans += base + cur;
    } else {
        // ここで終わりにする
        dfs(i+1, base + cur, 0);
        // 保持して次も見る
        dfs(i+1, base, cur);
    }
    return 0;
}

int main()
{
    cin >> S;
    dfs(0, 0, 0);
    printf("%lld\n", ans);
    return 0;
}


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

int charge(int);

int charge(int debt){
    debt *= 1.05;
    if(debt % 1000){
        debt = (debt / 1000) * 1000 + 1000;
    }
    return debt;
}

int main(int argc, const char * argv[]){
    
    int debt = 100000;
    int i = 0,n;
    scanf("%d",&n);
    
    while(i++ < n){
        debt = charge(debt);
    }
    printf("%d\n",debt);
    
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int,int> vii;
typedef vector<ll,ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
ll dua[40];
double pangkat (double x , ll p){
    double sum = 1;
    for(int i=1;i<=p;i++){
        sum *= x;
    }
    return sum;
}
int n,k;
double ans;
int main(){
    dua[0] = 1;
    for(int i=1;i<=35;i++){
        dua[i] = 2 * dua[i-1];
    }
    cin>>n>>k;

    for(int i=1;i<=n;i++){
        int idx;
        for(int j=0;j<=35;j++){
            if(dua[j] * i >= k){
                idx = j; break;
            }
        }
        double res;
        res = pangkat (2,idx);
        res = 1/res;

        ans += res;
    }
    ans /= n;
    printf("%.10lf\n",ans);



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


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

  int n,c;
  cin>>n>>c;

  vector<vector<int>> p(c,vector<int>(100005));
  rep(i,n){
    int s,t,x;
    cin>>s>>t>>x;
    x--;
    p[x][s]++;
    p[x][t+1]--;
  }

  rep(i,c){
    rep(j,100000){
      p[i][j+1]+=p[i][j];
    }
  }

  int ans=0;
  int ma=0;
  vector<bool> r(c,false);
  rep(i,100003){
    rep(j,c){
      if(!p[j][i] && r[j]){
        ma++;
        r[j]=false;
      }
    }
    rep(j,c){
      if(p[j][i] && !r[j]) {
        if(ma) ma--;
        else ans++;
        r[j]=true;
      }      
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 15324
# coding: utf-8

a, b = list(map(int, input().split()))

def compare(a, b):
	if a == b:
		return 0 # draw
	elif a == 1:
		return 1 # a
	elif b == 1:
		return -1 # b
	elif a > b:
		return 1 # a
	else:
		return -1 # b

cmp = compare(a, b)
if cmp == 0:
	print("Draw")
elif cmp == 1:
	print("Alice")
else:
	print("Bob")


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  cout << N*(N-1)/2 + M*(M-1)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define nax 101010
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pi pair<int ,int>
#define pii pair <pi,pi>
using namespace std;
int arr[200];
int fix[10];
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int r,g,b;
  cin >> r >> g >> b;
  int x = (g*10+b)%4;
  if(x)
    cout<< "NO\n";
  else
    cout<<"YES\n";
  return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    ll S = INF;
    vector<int> x(n);rep(i,n)cin>>x[i];
    for(int i=1; i<=100; i++){
        ll sum = 0;
        for(int j=0; j<n; j++){
            sum += (i-x[j])*(i-x[j]);
        }
        S = min(sum,S);
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
student_list = []
checkpoint_list = []
for _ in range(N):
    student_list.append(list(map(int, input().split())))
    
for _ in range(M):
    checkpoint_list.append(list(map(int, input().split())))
    
for i in student_list:
    compare_dict = {}
    for k, l in enumerate(checkpoint_list):
        
        manhattan_d = abs(i[0]-l[0])+abs(i[1]-l[1])
        
        if manhattan_d not in compare_dict.keys():
            compare_dict[manhattan_d] = k+1
        else:
            pass
    
    print(compare_dict[sorted(compare_dict.keys())[0]])

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [i64; n],
  }
  let mut a = a;
  a.sort();
  a.dedup();

  if a.len() == n {
    puts!("YES\n");
  } else {
    puts!("NO\n");
  }
}


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

#define M 100000
typedef long long ll;

int n, k;
ll T[M];

int check(ll p){
    int i = 0;
    for(int j = 0; j < k; j++){
        ll s = 0;
        while(s + T[i] <= p){
            s += T[i];
            i++;
            if(i == n)  return n;
        }
    }
    return i;
}

int solve(){
    ll left = 0;
    ll right = 100000*10000;
    ll mid;
    while(right - left > 1){
        mid = (right + left) / 2;
        int v = check(mid);
        if(v >= n){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++)  cin >> T[i];
    ll ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3880
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

type Weight = i32;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

fn dfs(g: &Graph, from: usize, d: Weight, color: &mut Vec<Weight>) {
    if color[from] != -1 {
        return;
    }
    color[from] = d;
    for e in g[from].iter() {
        let nd = (d + e.weight) % 2;
        dfs(g, e.dest, nd, color);
    }
}

fn main() {
    let n = read::<usize>();
    let mut g = graph_new(n);
    let mut index = 0;
    for i in 0..(n - 1) {
        let f = read::<usize>() - 1;
        let t = read::<usize>() - 1;
        let w = read::<Weight>();
        add_bi_edge(&mut g, &mut index, f, t, w);
    }
    let mut color = vec![-1; n];
    dfs(&g, 0, 0, &mut color);
    for i in 0..n {
        println!("{}", color[i]);
    }
}


Measured memory_bytes: 23164
import Foundation
// 第一引数には順列を生成したい配列を渡す
// 第二引数には順列を生成したい配列のサイズを渡す
func permutations(L:[[Int]],L_cnt:Int)->[[[Int]]]{
    // もしLが空なら[[]]を返す
    if L == []{
        return [[[]]]
    }
    // もしLのサイズが1なら[L]を返す
    else if L_cnt == 1{
        return [L]
    }
    //Lのサイズが2以上の時の処理
    else{
        //戻り値となる二次元配列を初期化
        var result:[[[Int]]] = []
        // Lの要素についてループを回す 
        for i in 0..<L_cnt{
            // 再帰
            for var x in permutations(L:Array(L[0..<i]+L[i+1..<L_cnt]),L_cnt:L_cnt-1){
                // 得られた二次元配列の要素である配列にL[i]を追加
                x.append(L[i])
                // 新しくできた順列をresultに追加
                result.append(x)
            }
        }
        // 生成した順列を返す
        return result
    }
}

// 2乗する関数
func pow2(n:Int)->Int{
    return n*n
}

// 標準入力からnを受け取る
let n = Int(readLine()!)!

// 標準入力からx,yを受け取る
// x,yを持っておく配列mを用意
var m:[[Int]] = []
for _ in 0..<n{

    // mに入力値を入れていく
    let xy = readLine()!.split(separator:" ").map{Int($0)!}
    m.append(xy)
}

// 順列の生成
var check = permutations(L:m,L_cnt:n)

// 答えを入れる変数を用意
var ans:Double = 0.0

// 順列全探索
for i in check{

    // iの要素について全探索
    for j in 0..<n-1{
    
        // i[j]とi[j+1]の距離をansに追加
        ans += sqrt(Double( pow2(n:i[j][0] - i[j+1][0]) + pow2(n:i[j][1] - i[j+1][1])))
    }
}

// n!で割って平均をとる
for i in 1...n{
    ans/=Double(i)
}

// ansの出力
print(ans)

Measured memory_bytes: 20764
#include<iostream>
#include<string.h>
#include<queue>
#define inf 1000000001
using namespace std;

int X[4]={0,1,0,-1};
int Y[4]={-1,0,1,0};
int H,W,A,si,sj;
char map[100][100];

bool in(int y,int x){
  if(y<0 || x<0 || y>=H || x>=W)return false;
  return true;
}
    
class State{
public:
  int y,x,muki,numL,numR;
  State(int y,int x,int muki,int l,int r):y(y),x(x),muki(muki),numL(l),numR(r){}
};

int main()
{
  int memo[100][100][4];
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      for(int k=0;k<4;k++)memo[i][j][k]=inf;
    }
  }
  queue<State> Q;
  cin>>H>>W>>A;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>map[i][j];
      if(map[i][j]=='S'){
	si=i;
	sj=j;
	map[i][j]='.';
      }
    }
  }
  Q.push(State(si,sj,2,0,0));
  memo[si][sj][0]=0;
  memo[si][sj][2]=0;
  int ans=inf;
  int a,b;
  while(!Q.empty()){
    State u=Q.front();
    //cout<<u.y<<" "<<u.x<<" "<<u.muki<<" "<<u.numL<<" "<<u.numR<<endl;
    Q.pop();
    if(u.numL>A || u.numR>A)continue;
    if(map[u.y][u.x]=='G'){
      ans=min(memo[u.y][u.x][u.muki],ans);
      continue;
    }
    a=u.y+Y[u.muki];
    b=u.x+X[u.muki];
    if(in(a,b)){
      if(map[a][b]!='#'){
	if(memo[a][b][u.muki]>=u.numL+u.numR){
	  memo[a][b][u.muki]=u.numL+u.numR;
	  Q.push(State(a,b,u.muki,u.numL,u.numR));
	}
      }
    }
    if(u.y==si && u.x==sj){}
    else {
      a=u.y+Y[(u.muki+1)%4];
      b=u.x+X[(u.muki+1)%4];
      if(in(a,b)){
	if(map[a][b]!='#'){
	  if(memo[a][b][(u.muki+1)%4]>=u.numL+u.numR+1){
	    memo[a][b][(u.muki+1)%4]=u.numR+u.numL+1;
	    if(memo[a][b][(u.muki+1)%4]<ans){
	      if(((u.muki+1)%4)%2==0){
		if(u.numL<A)Q.push(State(a,b,(u.muki+1)%4,u.numL+1,u.numR));
	      }
	      if(((u.muki+1)%4)%2==1){
		if(u.numR<A)Q.push(State(a,b,(u.muki+1)%4,u.numL,u.numR+1));
	      }
	    }
	  }
	}
      }
      a=u.y+Y[(u.muki+3)%4];
      b=u.x+X[(u.muki+3)%4];
      if(in(a,b)){
	if(map[a][b]!='#'){
	  if(memo[a][b][(u.muki+3)%4]>=u.numR+u.numL+1){
	    memo[a][b][(u.muki+3)%4]=u.numR+u.numL+1;
	    if(memo[a][b][(u.muki+3)%4]<ans){
	      if(((u.muki+3)%4)%2==0){
		if(u.numR<A)Q.push(State(a,b,(u.muki+3)%4,u.numL,u.numR+1));
	      }
	      if(((u.muki+3)%4)%2==1){
		if(u.numL<A)Q.push(State(a,b,(u.muki+3)%4,u.numL+1,u.numR));
	      }
	    }
	  }
	}
      }
    }
  }
  if(ans==inf)cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 17948
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

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

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

	int min = 100000;
	for (int i = 0; i < n - 1; ++i)
	{
		if(abs(a[n - 1] - 2 * a[i]) < min)
			min = abs(a[n - 1] - 2 * a[i]);
	}
	cout << min << "\n";
	return 0;
}

Measured memory_bytes: 256
s=input()
t=input()

n=0
a='?'*len(s)
for i in range(len(s)):
    k=0
    for j in range(len(t)):
        if i+j<len(s):
            if s[i+j]==t[j] or s[i+j]=='?':
                k+=1
    if k==len(t):
        n+=1
        a='?' * i + t + '?' * (len(s)-len(t)-i)
b=''

for i in range(len(s)):
    if s[i] != '?':
        b= b+s[i]
    elif a[i] != '?':
        b= b+a[i]
    else:
        b= b+'a'

if n==0:
    print('UNRESTORABLE')
else:
    print(b)


Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <array>

using namespace std;
typedef long long ll;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	char lc = 0, rc = 0;
	for (int li = 0, ri = s.length() - 1; li < ri; ) {
		lc = s[li];
		rc = s[ri];
		if (lc == 'x' && rc == 'x') {
			li++, ri--;
		} else if (lc == 'x') {
			ans++;
			li++;
		} else if (rc == 'x') {
			ans++;
			ri--;
		} else if (lc == rc) {
			li++;
			ri--;
		} else {
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
const ld RATE = 380000.0;
void good(){
  cout << "Heisei" << endl;
}
void bad(){
  cout << "TBD" << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ld x[n];
    string u[n];
    ld sum=0.0;
    F0R(i,n){
      cin >> x[i] >> u[i];

      if(u[i] == "BTC") sum += RATE*x[i];
      else sum += x[i];
    }

    cout<< std::setprecision(9) << sum << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll mod=1000000007;
ll MOD=INF;


int main() {
  int l,r,d;
  cin >> l >> r >> d;
  int a=(l-1)/d,b=r/d;
  cout << b-a << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	String s;
	StringBuilder sb=new StringBuilder();
	void solve(){
		Scanner sc=new Scanner(System.in);
		s=sc.next();
		for(int i=0;i<s.length();i++){
			if(s.charAt(i)=='0')sb.append('0');
			else if(s.charAt(i)=='1')sb.append('1');
			else if(s.charAt(i)=='B' && sb.length()>0) sb.deleteCharAt(sb.length()-1);
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 21716
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, k;
map<ll, ll> mp;

void solve() {
    ll c = 0;
    each(m, mp) {
        if (m.second + c >= k) {
            cout << m.first << endl;
            return;
        } else {
            c += m.second;
        }
    }
}

int main() {
    cin >> n >> k;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        mp[a] += b;
    }
    solve();
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int n,a;
  cin>>n>>a;
  if (n%500 <= a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
def e(x,y):
 A[y][x]='0'
 for d in range(-3,4):
  if 0<=x+d<8 and A[y][x+d]=='1':e(x+d,y)
  if 0<=y+d<8 and A[y+d][x]=='1':e(x,y+d)

for i in range(int(input())):
 print(f'Data {i+1}:')
 input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(*r,sep='')


Measured memory_bytes: 5632
N=int(input())
A=list(map(int,input().split()))
AP = 0
for a in A:
    if (a % 2 == 0):
        AP = AP - 1
        if ((a % 3 == 0) | (a % 5 == 0)):
            AP = AP + 1
if  AP == 0:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
#!/usr/bin/env python3
import math

def main():
    X = int(input())

    ex = []

    b = int(math.sqrt(X))
    ex.append(b * b)
    for b in range(2, 11):
        for p in range(3, 10):
            if b ** p <= X:
                ex.append(b ** p)
            else:
                break

    print(max(ex))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <iostream>
#include <utility>
#include <map>
#include <math.h>

using namespace std;

const int MOD = 1000000007;
typedef pair<int,int> ii;
typedef pair<long long,long long> il;

map <il,ii> mm;

long long fp(long long p){
	if(p==0) return 1;
	long long res = fp(p/2);
	res = (res*res)%MOD;
	if(p%2)res = (res*2)%MOD;
	return res;
}

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

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n;
	long long a,b,g;
	cin>>n;
	long long res = 1;
	for(int i = 0;i<n;i++){
		cin>>a>>b;
		if(a!=0||b!=0){
			if(a==0)mm[il(0,1)].first++;
			else if(b==0)mm[il(0,1)].second++;
			else{
				g = gcd(abs(a),abs(b));
				a/=g;
				b/=g;
				if((a>0)!=(b>0)){
					mm[il(abs(b),abs(a))].second++;
				}
				else mm[il(abs(a),abs(b))].first++;
			}
		}
		else mm[il(0,0)].first++;
	}
	if(mm.size()==1&&mm.count(il(0,0))>0){
		cout<<mm[il(0,0)].first<<endl;
		return 0;
	}
	ii ac;
	long long fac;
	for(map <il,ii>::iterator it = mm.begin();it!=mm.end();it++){
		if(it->first.second!=0){
			ac = it->second;
			fac = (fp(ac.first)+fp(ac.second)-1)%MOD;
			if(fac<0)fac+=MOD;
			res = (res*fac)%MOD;
		}
	}
	res = res +mm[il(0,0)].first-1;
	if(res<0)res+=MOD;
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 15660
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double Double;
const ll MOD=1e9+7;
const int maxn=1050;
int n;
struct node
{
    Double x,y,r;
}a[maxn];
int s=1011,t=1012;
Double dis(int p,int q){
     Double ans=sqrt((a[p].x-a[q].x)*(a[p].x-a[q].x)+(a[p].y-a[q].y)*(a[p].y-a[q].y))-a[p].r-a[q].r;
     if(ans>=0) return ans;
     return 0.0;
}
struct Node
{
    Node(int x,Double d):x(x),d(d){}
    int x;
    Double d;
    bool operator <(const Node&t)const{
        return d>t.d;
    }
};
bool vis[maxn];
Double D[maxn];
Double dijkstra(){
    priority_queue<Node> q;
    for (int i = 0; i < n+10; ++i)
    {
        D[i]=1e20;
    }
    q.push(Node(s,0));
    D[s]=0;
    while(!q.empty()){
        Node u=q.top();
        q.pop();
        if(vis[u.x]) continue;
        vis[u.x]=true;
        for (int i = 1; i <= n; ++i)
        {
            if(!vis[i]&&D[i]>u.d+dis(u.x,i)) q.push(Node(i,u.d+dis(u.x,i))),D[i]=u.d+dis(u.x,i);
        }
    }
    return D[t];
}
int main(int argc, char const *argv[])
{
    scanf("%Lf%Lf", &a[s].x,&a[s].y);
    scanf("%Lf%Lf", &a[t].x,&a[t].y);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%Lf%Lf%Lf", &a[i].x,&a[i].y,&a[i].r);
    }
    a[n+1]=a[s];
    a[n+2]=a[t];
    s=n+1,t=n+2;
    a[s].r=a[t].r=0;
    n+=2;
    printf("%.9Lf\n", dijkstra());
    return 0;
}

Measured memory_bytes: 10476
fun main(args: Array<String>) {
    var (a,b,c,d) = readLine()!!.split(" ").map { it.toInt() }
    while(true){
        c -= b
        if(c <= 0) {
            println("Yes")
            break
        }
        a -= d
        if(a <= 0){
            println("No")
            break
        }
    }
}

Measured memory_bytes: 36356
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

#define MOD 1000000007

int main(){
  string s;
  cin >> s;
  int K;
  cin >> K;

  int y=s.size();
  int si=min(y,K);

  vector<string> x;
  for(int i=1;i<=si;i++){
    for(int j=0;j<=s.size()-i;j++){
      string a;
      for(int k=j;k<i+j;k++){
        a+=s.at(k);
      }
      x.push_back(a);
    }
  }
  sort(x.begin(),x.end());
  x.erase(unique(x.begin(),x.end()),x.end());
  cout << x.at(K-1) << endl;

  return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int r,s,p;
int solve(string str){
    string t = "rps";
    auto comp = [&](char a, char b){
        if(a == 'r' && b == 's') return r;
        if(a == 's' && b == 'p') return s;
        if(a == 'p' && b == 'r') return p;
        else return 0;
    };
    vector<vector<int>>dp(3,vector<int>(str.size() + 1,0LL));
    for(int i = 0; i < str.size(); ++i){
        for(int j = 0; j < 3; ++j){
            for(int k = 0; k < 3; ++k){
                if(k == j) continue;
                dp[k][i + 1] = max(dp[k][i + 1], dp[j][i] + comp(t[k],str[i]));
            }
        }
    }
    return max({dp[0].back(),dp[1].back(),dp[2].back()});
}
int main(){
    int N, K; cin >> N >> K;
    cin >> r >> s >> p;
    string str; cin >> str;
    vector<string>chain(K);
    for(int i = 0; i < str.size(); ++i){
        chain[i % K].push_back(str[i]);
    }
    int sum = 0;
    for(auto str : chain)
        sum += solve(str);
    cout << sum << endl;
}


Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int N;
	cin >> N;

	int sum = 0;

	int init = N;

	do {
		sum += N % 10;
		N = (N - N % 10) / 10;
	} while (N > 0);

	Yes(init % sum == 0);

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int L, R,  A, B, C, D;
  cin >> A >> B >> C >> D;
  L=A+B;
  R=C+D;
  
  if(L > R){
    cout << "Left" << endl;
  }else if(L == R){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();
		
		int[] x = new int[10];
		
		x[0] = b - a;
		x[1] = c - a;
		x[2] = d - a;
		x[3] = e - a;
		x[4] = c - b;
		x[5] = d - b;
		x[6] = e - b;
		x[7] = d - c;
		x[8] = e - c;
		x[9] = e - d;
		
		int num = 0;
		
		for(int i = 0; i < 10; i++) {
			if(x[i] > k) {
				num++;
			}
		}
		
		if(num == 0) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}
		
	}
}


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

int main() {
  string s;
  cin >> s;
  bool p = false;
  rep(bit, 1<<4) {
    string t;
    if (bit & 1<<0) t += "A";
    t += "KIH";
    if (bit & 1<<1) t += "A";
    t += "B";
    if (bit & 1<<2) t += "A";
    t += "R";
    if (bit & 1<<3) t += "A";
    if (s == t) p = true;
  }
  if (p) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3576
#include<cstdio>
#include<cstring>
#include<algorithm>
int N,sum[6010],pos[6010],nxt[6010];
char S[6010],lt[6010][6010];
bool cmp(int i,int j){
	if(sum[i]!=sum[j])return sum[i]>sum[j];
	if(lt[i][j])return lt[i][j]==1;
	return i<j;
}
int main(){
	scanf("%d%s",&N,S);
	for(int i=0;i<N*2;i++)sum[i+1]=sum[i]+(S[i]=='b'?1:-1),pos[i]=i;
	nxt[N*2]=N*2;
	for(int i=N*2;i--;)nxt[i]=sum[i+1]?nxt[i+1]:i+1;
	for(int i=N*2;i>=0;i--){
		for(int j=N*2;j>=0;j--){ 
			if(i==j)lt[i][j]=0;
			else if(S[i]!=S[j])lt[i][j]=(S[i]<S[j]?-1:1);
			else if(sum[i+1]>0&&sum[j+1]>0)lt[i][j]=lt[i+1][j+1];
			else lt[i][j]=sum[i+1]>0?1:sum[j+1]>0?-1:0;
		}
	}
	std::sort(pos,pos+N*2,cmp);
	int r=0;
	for(;;){
		int i=0;
		while(i<N*2&&sum[pos[i]]>0&&pos[i]<r)i++;
		if(i==N*2||sum[pos[i]]<=0){
			for(int pa=r,pb=r;pb<N*2;pb++)if(S[pb]=='b'){
				if(pa>=r)printf("ab"),r=pb;
				for(pa++;pa<N*2&&S[pa]=='b';pa++);
			}
			puts("");
			return 0;
		}
		for(int j=sum[pos[i]];j--;)putchar('b');
		for(int j=pos[i];j<nxt[pos[i]];j++)putchar(S[j]);
		r=nxt[pos[i]];
	}
}

Measured memory_bytes: 35328
A, B, K = map(int,input().split())
for i in range(K):
  if i % 2 == 0:
    if A % 2 == 1: A -= 1
    A //= 2
    B += A
  else:
    if B % 2 == 1: B -= 1
    B //= 2
    A += B
print(A, B)    

Measured memory_bytes: 38384
var t:longint;        //A的个数在32位范围内
    a:int64;          //结果会爆int
    c:char;           //滚动省空间
begin
  while not eoln do   //一直读到换行
  begin
    read(c);          //读入一个
    if c='A' then     //如果是A
      inc(t);         //记录值加一
    if c='B' then     //如果是B
    begin
      read(c);        //读入
      if c='C' then   //如果是C（有效字符）
      begin
        inc(a,t);     //结果加记录值
        continue;     //下一个循环
      end
      else            //如果不是C（无效字符）
        if c='A' then //如果是A（因为A被吞了）所以要分开计算
          t:=1        //记录值为1
        else          //否则
          t:=0;       //记录值为0
    end;
    if c='C' then     //如果是单个的C（无效字符）
      t:=0;           //记录值为0
  end;
  writeln(a);         //输出结果
end.

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> jobs(m+1);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if(a > m) continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for(int i = m-1; i >= 0; --i) {
    for(int b : jobs[i]) {
      q.push(b);
    }
    if(!q.empty()) {
      ans += q.top(); q.pop();
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5504
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = len(str(N))

C = []
for k in range(10):
    if not k in D:
        C.append(k)

def num(a):
    if a!='' and (len(a) > n  or int(a)>=N):
        if int(a) >= N:
            return a
        return 114514
    d=1145141919
    for c in C:
        d =min(d, int(num(a + str(c))))
    return d

print(num(''))


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

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

  int a1 = a, b1 = b;
  if(a>b)
  {
    a1=b;
    b1=a;
  }
  int b2 = b1, c2 = c;
  if(b1>c)
  {
    b2=c;
    c2=b1;
  }
  int a3 = a1, b3 = b2;
  if(a1>b2)
  {
    a3=b2;
    b3=a1;
  }

  cout <<a3 <<" "<<b3 <<" "<<c2 <<endl;
  return 0;
}

Measured memory_bytes: 1164
h,w = gets.chomp.split.map(&:to_i)
gs = h.times.map{gets.chomp.chars}
d = [[0,1],[0,-1],[1,0],[-1,0]]
ans = true
h.times do |i|
	w.times do |j|
		next if gs[i][j] == "."
		flag = false
		d.each do |x,y|
			next if i+x >= h || i+x < 0 || j+y >= w || j+y < 0
 			if gs[i][j] == "#" && gs[i+x][j+y] == "#"
				flag = true
			end
		end
		ans = false if !flag 
	end
end

puts ans ? "Yes" : "No"

Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    unsigned long long n, m; cin >> n >> m;
    //const int max_a = 1000000000;
    //vector<int> t(max_a+1, 0);
    map<unsigned long long, unsigned long long> t;
    vector<unsigned long long> k;
    unsigned long long a;
    for(unsigned long long i=0uLL;i<n;++i) {
        cin >> a;
        ++t[a];
        k.push_back(a);
    }
    unsigned long long b,c;
    for(unsigned long long i=0uLL;i<m;++i) {
        cin >> b >> c;
        t[c] += b;
        k.push_back(c);
    }
    sort(k.begin(),k.end(),std::greater<unsigned long long>());

    unsigned long long z = 0uLL, pval = 0uLL, dec;
    vector<unsigned long long>::iterator itr = k.begin();
    while(n>0) {
        //cout << *itr << " " << t[*itr] << " " << z << endl;
        if(*itr!=pval) {
            pval = *itr;
            dec = min(n, t[*itr]);
            n -= dec;
            z += dec*(*itr);
        }
        ++itr;
    }
    cout << z << endl;
    return 0;
}


Measured memory_bytes: 14320
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
S = [input() for _ in range(H)]

ans = 0
searched = [[0]*W for _ in range(H)]
dx = [0, -1, 0, 1]
dy = [1, 0, -1, 0]

for i in range(H):
	for j in range(W):
		if searched[i][j] or S[i][j] == ".":
			continue
		num_b = 0
		num_w = 0
		q = deque()
		q.append((i, j))
		num_b += 1
		searched[i][j] = 1
		while q:
			y, x = q.popleft()
			for k in range(4):
				ny = y + dy[k]
				nx = x + dx[k]
				if 0 <= ny <= H-1 and 0 <= nx <= W-1 and not searched[ny][nx] and S[ny][nx] != S[y][x]:
					searched[ny][nx] = 1
					if S[ny][nx] == "#":
						num_b += 1
					else:
						num_w += 1
					q.append((ny, nx))
		ans += num_b*num_w

print(ans)

Measured memory_bytes: 71000
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

#define white 0
#define gray 1

int M[110][110];
vector<int> color(110,white),d(110),f(110);
int t=0;
int n;

void dfs(int u){
  color[u]=gray;
  d[u]=++t;
  for(int v=0;v<n;v++){
    if(M[u][v] && color[v]==white) dfs(v);
  }
  f[u]=++t;
}

int main(){
  cin>>n;
  
  rep(i,n){
    rep(j,n) M[i][j]=0;
  }
  
  int x,y,z;
  rep(i,n){
    cin>>x>>y;
    x--;
    rep(j,y){
      cin>>z;
      z--;
      M[x][z]=1;
    }
  }

  rep(i,n){
    if(color[i]==white) dfs(i);
  }
  
  rep(i,n) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  
  return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String S = sc.nextLine();
		
		int end = 0;
		String[] map = {"dream", "dreamer", "erase", "eraser"};
		while(end < S.length()) {
			boolean delete = false;
			for (String target: map) {
				if (S.length() - end - target.length() < 0) {
					continue;
				}
				
				if (S.substring(S.length() - end - target.length(), S.length() - end).equals(target)) {
					delete = true;
					end += target.length();
					break;
				}
			}
			
			if (!delete) {
				System.out.println("NO");
				return;
			}
		}
		
		System.out.println("YES");
	}
}

Measured memory_bytes: 30412
import numpy as np

def gcd(a,b):
    if a % b == 0:
        return b
    return gcd(b, a%b)


N, X = map(int, input().split())
x = list(map(int, input().split()))

s = np.array(x)
s = abs(s-X)

if len(s) == 1:
    print(s[0])
    exit()

for i in range(1, len(s)):
    if i == 1:
        D = gcd(s[i],s[i-1])
    D = gcd(s[i], D)

print(D)


Measured memory_bytes: 38124
#include <iostream>

using namespace std;

int main()
{
    int x,y,suma = 0;
    cin >> x >> y;
    int a[y];
    for (int i = 0; i < y; i++){
        cin >> a[i];
        suma += a[i];
    }
    if (suma <= x){
        cout << x-suma;
    }
    else{
        cout << -1;
    }
    return 0;
}


Measured memory_bytes: 3688