akhauriyash/Code-Regression huggingface dataset:
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, label)
  size = queue.size
  index = queue.index{|entry| entry[0] >= label} || size
  return queue[index][1] if index < size && queue[index][0] == label

  return nil if index > 0 && !label.start_with?(queue[index - 1][0])
  queue.slice!(index..-1) if index < size && !queue[index][0].start_with?(label)

  nodes = {}
  queue.insert(index, [label.dup, nodes])
  nodes
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow if reachable_from[arrow.sink]
  end

  limit = n * arrows.map{|arrow| arrow.label.size}.max

  result = ''
  queue = [['', {start => true}]]
  until queue.empty?
    label, nodes = queue.shift
    result << label
    return result if nodes[goal]
    return nil if result.size > limit

    size = label.size
    queue.each do |next_label, _|
      next_label.slice!(0...size)
    end

    nodes.each do |node, _|
      outs[node].each do |arrow|
        new_nodes = push(queue, arrow.label)
        new_nodes[arrow.sink] = true if new_nodes
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = a.times.map{
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  }

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 9580
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
B = sorted(set(A))
d = {}
for b in B:
    d[b] = 0
for a in A:
    d[a] += 1

C = [d[b] for b in B]

ans = len(B)
x = sum(c-1 for c in C)
if x % 2 == 1:
    ans -= 1

print(ans)


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

int main(){
    vector<int> dp(3,0);
    vector<int> nums(3);
    int K;
    cin>>K;
    for(int i=0;i<K;i++){
        for(int c=0;c<3;c++){
            cin>>nums[c];
        }
        vector<int> n_dp(3,0);
        for(int j=0;j<3;j++){
            for(int j2=0;j2<3;j2++){
                if(j != j2){
                    n_dp[j2] = max(n_dp[j2],dp[j]+nums[j2]);
                }
            }
        }
        dp=n_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]})<<endl;
    return 0;
}

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

int N,A,B,P[110];

int main(){
	cin >> N >> A >> B;
	int a = 0,ab = 0,b = 0;
	for(int i=0;i<N;i++){
		cin >> P[i];
		if(P[i]<=A) a++;
		else if(P[i]>=B+1) b++;
		else ab++;
	}
	cout << min(a,min(ab,b)) << endl;
}

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

l=[[0]*10 for _ in range(10)]
for i in range(1, n+1):
    t=str(i)
    l[int(t[0])][int(t[-1])]+=1

ans=0
for i in range(1, 10):
    for j in range(1, 10):
        ans+=l[i][j]*l[j][i]
print(ans)


Measured memory_bytes: 3060
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    A = [a[0] for a in AB]
    B = [b[1] for b in AB]
    dp = [[10**9+7]*(H+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0
    for i in range(N):
        for j in range(1, H+1):
            lessHP = max(j - A[i], 0)
            dp[i+1][j] = min(dp[i+1][lessHP] + B[i], dp[i][j])
    print(dp[N][H])


if __name__ == '__main__':
    main()


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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1e5 + 5;

int n, ar[N], ans;

main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%d", &ar[i]);

    sort(ar + 1, ar + n + 1);

    ans = 1;

    for (int i = 1; i < n; i++)
    {
        if ( abs(ar[i] - ar[n] / 2) < abs(ar[ans] - ar[n] / 2) )
            ans = i;
    }
    for (int i = 1; i < n; i++)
    {
        if ( abs(ar[i] - (ar[n] + 1) / 2) < abs(ar[ans] - (ar[n] + 1) / 2) )
            ans = i;
    }
    cout << ar[n] << " "  << ar[ans] << endl;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
int main() {
	while (1) {
		int n, k[10001];
		int hirota = 0;
		bool bol = false;
		memset(k, 0, sizeof(k));
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> k[i];
			if (k[i] > 1)bol = true;
			if (k[i] == 0)hirota++;
		}
		if (bol == false) {
			cout << "NA" << endl;
			//return 0;
		}
		else if (n == 1) {
			cout << 2 << endl;
		}
		else {
			cout << n + 1-hirota << endl;
		}
	}
}

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

using namespace std;

int main()
{
    int n=1;
    
    cin >> n;
    
    if(n==1)
        cout << n;
    else
    {
        if(n%2==0)
            cout << n/2;
        else
            cout << n/2+1;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n)
    {
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    vector<int> d1, d2;
    rep(i, n)
    {
        if (i % 2 == 0) {
            d1.push_back(d[i]);
        } else {
            d2.push_back(d[i]);
        }
    }

    int s = d[0];
    if (n >= 2) {
        s = min(s, 24 - d[n - 1] - d[n - 2]);
    }

    for (int i = 1; i < d1.size(); i++) {
        s = min(s, d1[i] - d1[i - 1]);
    }
    for (int i = 1; i < d2.size(); i++) {
        s = min(s, d2[i] - d2[i - 1]);
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string a;
    cin>>a;
	int l=a.size();
    for(register int i=0;i<l;i++)
    {
        if(a[i]=='C')
        {
            for(register int j=i+1;j<l;j++)
            {
                if(a[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
//use proconio::marker::{Bytes, Chars};

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        k: usize,
    }
    let mut div = 7 % k;
    for i in 1..1000000 {
        if div == 0 {
            println!("{}", i);
            return;
        }
        div = (div * 10 + 7) % k;
    }
    println!("-1");
}


Measured memory_bytes: 2072
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


n = int(input())
lists = [input().split() for i in range(n)]

#print(lists)

ans = 0

for i in range(n):
	if lists[i][1] == 'JPY':
		ans = ans + float(lists[i][0])
	else:
		ans = ans + float(lists[i][0])*380000
		
print(ans)


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

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<1000000007>;

mint fact[202020];
mint factinv[202020];

void init() {
    fact[0] = 1;
    for (int i = 1; i < 202020; i++) {
        fact[i] = fact[i - 1] * i;
    }
    factinv[202020 - 1] = fact[202020 - 1].inv();
    for (int i = 202020 - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * (i + 1);
    }
    assert(factinv[0] == 1);
}

mint ncr(int n, int r) {
    return fact[n] * factinv[r] * factinv[n - r];
}

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

    int n, k;
    cin >> n >> k;
    vector<vector<int>> adj(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    mint ans = k;
    function<void(int, int)> dfs = [&](int v, int p) {
        int kouho = k - 1;
        if (p != -1) kouho--;
        for (int s : adj[v]) {
            if (s == p) continue;
            ans *= kouho;
            kouho--;
            dfs(s, v);
        }
    };
    dfs(0, -1);

    cout << ans << endl;
}

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

const int N = 2020, inF = N * N;

int n, r[N], l[N], pmax[N];
int ans = inF;
string a, b;

string shift_R(string s, int l) {
	return s.substr(n - l) + s.substr(0, n - l);
}

string shift_L(string s, int l) {
	return s.substr(l) + s.substr(0, l);
}

int dis(int a, int b) {
	return min(fabs(a - b), n - fabs(a - b));
}

void check(int dex) {
	vector<int> vec;
	for (int i = 0; i < n; i++)
		if(a[i] != b[(i + dex) % n])
			vec.push_back(i);
	vec.push_back(n);
	sort(vec.begin(), vec.end(), [](int a, int b) {
		return l[a] < l[b];
	});
	
	int m = vec.size();
	memset(pmax, 0, sizeof pmax);
	for (int i = m - 1; ~i; i--)
		pmax[i] = max(pmax[i + 1], r[vec[i]]);
	for (int i = 0; i < m; i++) {
		int help = l[vec[i]] << 1;
		help += pmax[i + 1] + dis(pmax[i + 1], dex);
		ans = min(ans, help + m - 1);
	}
	ans = min(ans, l[vec.back()] + dis((n - l[vec.back()]) % n, dex) + m - 1);
	
	sort(vec.begin(), vec.end(), [](int a, int b) {
		return r[a] < r[b];
	});
	memset(pmax, 0, sizeof pmax);
	for (int i = m - 1; ~i; i--)
		pmax[i] = max(pmax[i + 1], l[vec[i]]);
	for (int i = 0; i < m; i++) {
		int help = r[vec[i]] << 1;
		help += pmax[i + 1] + dis((n - pmax[i + 1]) % n, dex);
		ans = min(ans, help + m - 1);
	}
	ans = min(ans, r[vec.back()] + dis(r[vec.back()], dex) + m - 1);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> a >> b;
	n = a.length();
	r[0] = -1;
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; ~j; j--) {
			if(b[(i + j) % n] == '1')
				r[i] = j;
			if(b[(i - j + n) % n] == '1')
				l[i] = j;
		}
		
		if(shift_L(a, i) == b)
			ans = min(ans, i);
		if(shift_R(a, i) == b)
			ans = min(ans, i);
	}
	if(r[0] == -1) {
		cout << (ans == inF? -1: ans);
		return 0;
	}
	for (int i = 0; i < n; i++)
		check(i);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = 0
for i, v in enumerate(b_list):
  enemy = a_list[i]
  if enemy >= b_list[i]:
    a_list[i] -= b_list[i]
    ans += b_list[i]
    b_list[i] = 0
  else:
    a_list[i] = 0
    b_list[i] = b_list[i] - enemy
    ans += enemy
    enemy = a_list[i + 1]
    if a_list[i + 1] >= b_list[i]:
      a_list[i + 1] -= b_list[i]
      ans += b_list[i]
      b_list[i] = 0
    else:
      a_list[i + 1] = 0
      b_list[i] = b_list[i] - enemy
      ans += enemy
print(ans)

Measured memory_bytes: 19004
from sys import stdin,stdout
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
import itertools
N = int(input())
L = list(map(int, input().split()))
if N < 3:
    print(0)
    exit()
ans = 0
for bars in itertools.combinations(L, 3):
    if max(bars) >= sum(bars) - max(bars):
        continue
    if bars[0] == bars[1]:
        continue
    if bars[1] == bars[2]:
        continue
    if bars[0] == bars[2]:
        continue
    ans += 1
print(ans)

Measured memory_bytes: 68128
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a;
  ci(a);
  vec b(a),c(a);
  For(i,0,a){
    ci(b[i]);
    c[i]=b[i];
    }
  sort(b,b);
  ll an=b[a-1],ans=b[a-2];
  For(i,0,a){
    if(c[i]==an)
      co(ans);
    else
      co(an);
    }
  }

Measured memory_bytes: 4736
/*
i个位置相同
	C(n,i)*C(m,i)*Fi :选i个位置相同
	C(n-i,m-i)* 
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
#define N 500005

ll n,m,ans;

ll F[N], Finv[N], inv[N];///F是阶层 Finv是逆元的阶层
void init(){
    inv[1] = 1;
    for(int i = 2; i < N; i++)
        inv[i] = (mod - mod/i) * 1ll * inv[mod % i] % mod;
    F[0] = Finv[0] = 1;
    for(int i = 1; i < N; i++){
        F[i] = F[i-1] * 1ll * i % mod;
        Finv[i] = Finv[i-1] * 1ll * inv[i] % mod;
    }
}
int C(int n, int m){ 
    if(m < 0 || m > n) return 0;
    return F[n] * 1ll * Finv[n-m] % mod * Finv[m] % mod;
}
int main(){
	cin>>n>>m;
	init();
	ans=C(m,n)*F[n]%mod;
	for(int i=1;i<=n;i++){
		ll flag=(i%2)?-1:1;
		ll tmp = C(n,i);
		tmp = tmp*C(m-i,n-i)%mod;
		tmp = tmp*F[n-i]%mod;
		ans=(ans+flag*tmp+2*mod)%mod;
	}
	//cout<<ans<<'\n';	
	cout<<ans*C(m,n)%mod*F[n]%mod<<'\n';
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
#define dpair pair<double,double>

template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
template <typename Val>
void show_vec(vector<Val> *v){
  cout<<endl;
  rep(i,v->size()){
    cout<<v->at(i)<<" ";
  }
  cout<<endl;
}
//---------------------------------------------------------------
int main(){

  int X,Y;
  cin>>X>>Y;
  string ans ="No";
  rep(i,X+1){
    int t = i;
    if(t*4+(X-t)*2==Y){
      ans ="Yes";
      break;
    }

  }










  cout<<ans<<endl;




}


Measured memory_bytes: 3616
import sys
from collections import Counter

n = int(input())
d_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(d_ls)
res = 1
if d_ls[0] != 0 or ct[0] > 1:
    print(0)
else:
    for i, count in sorted(ct.items(), key=lambda x:x[1]):
        if i == 0:
            continue
        res = (res * (ct[i-1] ** count)) % 998244353
    print(res)

Measured memory_bytes: 22044
h,w,a,b = map(int,input().split())
s = [["0"]*w for _ in range(h)]
for i in range(b):
    for j in range(a): s[i][j] = "1"
for i in range(h-b):
    for j in range(w-a):
        s[h-1-i][w-1-j]: s[i][j] = "1"
for i in range(h): print("".join(s[i]))

Measured memory_bytes: 16788
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::{BTreeMap,BTreeSet};
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! tf {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

fn main() {
    let (n,z) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1])
    };
    let xs = read_vec_i64();
    let total = xs.iter().sum::<i64>();
    if total == z {
        println!("{}", n);
    }
    else {
        let mut xs = xs.clone();
        xs.sort();
        let mut t = 0;
        for (i,&x) in xs.iter().enumerate() {
            if t + x > z {
                println!("{}", i);
                return;
            }
            t += x;
        }
        println!("{}", n-1);
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    //ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A = IL()

A.sort()
ABS = []
for i in range(1,N):
    ABS.append(A[i]-A[i-1])

ABS.sort()
num = A[1]
cnt = 0
for i in range(num+1,0,-1):
    cnt = 0
    for j in range(N):
        if A[j]%i==0:
            continue
        else:
            cnt += 1
        if cnt == 2:
            break
    else:
        print(i)
        exit()

Measured memory_bytes: 23160
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll I,O,T,J,L,S,Z,ans=0;
int main()
{
    cin>>I>>O>>T>>J>>L>>S>>Z;
    ans+=O;
    if(!I || !J || !L)ans+=I/2*2+J/2*2+L/2*2;
    else{
        ans+=I+J+L;
        if((I&1)==(J&1) && (J&1)==(L&1));
        else --ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    if i == 0:
        ans +=B[i]
    elif i == N-1:
        ans +=B[i-1]
    else:
        if B[i-1]>=B[i]:
            ans += B[i]
        else:
            ans +=B[i-1]

print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String akihabara = "AKIHABARA";
		String kihbr = "KIHBR";
		String s = scanner.nextLine();

		int i;
		int j = 0;
		int k = 0;
		for(i = 0; i < s.length(); i++){
			if(
				j + 1 < akihabara.length() &&
				akihabara.charAt(j) == 'A' &&
				akihabara.charAt(j) != s.charAt(i)
			) {
				j++;
			}

			if(j >= akihabara.length() || akihabara.charAt(j) != s.charAt(i)) {
				System.out.println("NO");
				return;
			}
			if(s.charAt(i) != 'A') {
				if(s.charAt(i) == kihbr.charAt(k)) {
					k++;
				} else {
					System.out.println("NO");
					return;
				}
			}
			j++;
		}
		if(k == kihbr.length()) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 23636
def main():
    import sys
    input  = sys.stdin.readline

    n,m = map(int,input().split())
    dp = [[float("inf")]*(10**5+1) for i in range(n+1)]
    dp[0][0] = 0
    for i in range(n):
        w,v = map(int,input().split())
        for j in range(10**5+1):
            if j-v >= 0:
                dp[i+1][j] = min(dp[i][j],dp[i][j-v]+w)
            else:
                dp[i+1][j] = dp[i][j]
    ans = 0

    for i in range(10**5+1):
        if dp[n][i] <= m:
            
            ans = i
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 303992
#include <stdio.h>
#include <stdlib.h>

void maxHeapify(int *A, int i, int H){
	int l, r, largest, temp;
	l = 2 * i;
	r = 2 * i + 1;

	if(l <= H && A[l] > A[i])
		largest = l;
	else
		largest = i;
	if(r <= H && A[r] > A[largest])
		largest = r;

	if(largest != i){
		temp = A[i];
		A[i] = A[largest];
		A[largest] = temp;
		maxHeapify(A, largest, H);
	}
}

int main(){
	int H, *A, i;

	scanf("%d", &H);
	A = (int *)malloc(sizeof(int) * (H+1));
	for(i = 1; i <= H; i++)
		scanf("%d", &A[i]);

	for(i = H/2; i >= 1; i--)
		maxHeapify(A, i, H);

	for(i = 1; i <= H; i++)
		printf(" %d", A[i]);
	printf("\n");

	free(A);
	return 0;
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n, k;
  cin >> n >> k;
  vi p(n);
  rep(i,n) cin >> p.at(i);
  vector<double> v(n);
  rep(i,n) v[i] = (double)(1+p[i])/2;
  double sum =0;
  rep(i,k) sum += v[i];
  double ans = sum;
  rep(i,n-k) {
    sum -= v[i];
    sum += v[i+k];
    ans = max(ans,sum);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	//
        Scanner sc = new Scanner(System.in);
        //
        String input = "";
        //???????????????
        int[] array = new int[26];
        //??£?¨?
        int intTemp;
        //?????£?????????????????????????????´??? true?????????????????????
        while(sc.hasNext()){
        	//1????????£?????????
            input += sc.nextLine();
        }
        //?????£??????????????????????????????????????°?????????
        for(int i = 0; i < input.length(); i++){
        	//
            intTemp = input.charAt(i);
            //
            if('A' <= intTemp && intTemp <= 'Z'){
                array[intTemp - 'A']++;
            }else if('a' <= intTemp && intTemp <= 'z'){
                array[intTemp - 'a']++;
            }
        }
        for(int i = 0; i < array.length; i++){
            System.out.println((char)('a' + i) + " : " + array[i]);
        }
    }
}

Measured memory_bytes: 26168
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():
 
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'
 
    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5
 
 
    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
 
        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
 
 
    def equals(self,another):
 
        ret = False;
 
        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True
 
        return ret
 
 
 
num_dice = int(input())
DICE = []
 
for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True
 
for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break
 
 
if FLG == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 6404
/**
 *    author:  tourist
 *    created: 25.11.2017 13:04:32       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  string need = "AKIHABARA";
  int ptr = 0;
  for (int i = 0; i < 9; i++) {
    if (ptr < (int) s.length() && need[i] == s[ptr]) {
      ptr++;
    } else {
      if (need[i] != 'A') {
        puts("NO");
        return 0;
      }
    }
  }
  if (ptr != (int) s.length()) {
    puts("NO");
    return 0;
  }
  puts("YES");
  return 0;
}


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

public class Main{
    
    public static void main(String[] args) throws IOException {
        Reader.init();
        int N=Reader.nextInt();
      	print(N*N*N);
    }

    static int mod=1000000007;
    
    public static void read(int arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.nextInt(); } }
    public static void read(String arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.next(); } }
    
    public static void print(Object O){ System.out.println(O); }
    
    public static void display(int arr[]){ System.out.println(Arrays.toString(arr)); }
    public static void display(int arr[][], int N){ for(int i=0;i<N;i++){ System.out.println(Arrays.toString(arr[i])); } }
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init() {
        reader=new BufferedReader(new InputStreamReader(System.in));
        tokenizer=new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) {
            tokenizer=new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException { return Integer.parseInt(next()); }
    static double nextDouble() throws IOException { return Double.parseDouble(next()); }
    static long nextLong() throws IOException { return Long.parseLong(next()); }
    static String nextLine() throws IOException { return reader.readLine(); }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 1e5 + 5;
int a[N], b[N];

const ll mod = 1e9 + 7;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

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

  ll ans = 1;
  if (a[1] > b[1] || a[n] < b[n] || a[n] != b[1]) ans = 0;
  for (int i = 2; i <= n - 1; i++) {
    if (a[i] == a[i - 1] && b[i] == b[i + 1]) {
      ans = (ans * min(a[i], b[i])) % mod;
    }
    if (a[i] != a[i - 1]) {
      if (b[i] < a[i]) ans = 0;
    }
    if (b[i] != b[i + 1]) {
      if (a[i] < b[i]) ans = 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int dp[200][200][200] = {0};

int gcd(int big,int small){
	int r = big % small;
	while( r != 0){
		big = small;
		small = r;
		r = big % small;
	}
	return small;
}

int main(){
	int K;
	cin>>K;
//
	ll ans_sum = 0;

	for(int i = 1; i <= K; i++){
		for(int j = 1; j <= K; j++){
			for(int h = 1; h <= K; h++){
				int large;
				int normal;
				int small;
				
				if( h >= j && h >= i ){
					large = h;
					normal = max(j,i);
					small = min(j,i);
				}
				else if( j >= h && j >= i ){
					large = j;
					normal = max(h,i);
					small = min(h,i);
				}
				else{
					large = i;
					normal = max(h,j);
					small = min(h,j);
				}
					
				if(dp[large-1][normal-1][small-1] == 0){
					ll ggg = gcd(h,gcd(j,i));
					ans_sum += ggg;
					dp[large-1][normal-1][small-1] = ggg;
				}
				else{
					ans_sum += dp[large-1][normal-1][small-1];
				}

			}
		}
	}
	cout<<ans_sum<<endl;
	return 0;
}



Measured memory_bytes: 19772
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 998244353;
ll dp[200005];
ll pre[200005];


void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<pair<ll,ll>> v(k);
	for (int i = 0; i < k; ++i)
	{
		cin>>v[i].first>>v[i].second;
	}
	memset(pre, 0, sizeof pre);
	memset(dp, 0, sizeof dp);
	dp[1] = 1;
	sort(v.begin(),v.end());
	for (ll i = 2; i <= n; ++i)
	{
		pre[i-1] = (pre[i-2] + dp[i-1])%mod;
		for(int j = 0; j< k;j++)
		{

			ll low = max(0ll,i-(v[j].second+1));
			ll high = max(0ll,i-(v[j].first));
			dp[i] = (dp[i] + pre[high]-pre[low])%mod;
		}
		// cout<<dp[i]<<" ";
	}
	cout<<(dp[n]+mod)%mod<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 6724
# -*- coding: utf-8 -*-
import sys
n,m=map(int, input().split())

if m == 0:
    if n == 1:
        print("0")
        sys.exit(0)
    res = "1"
    for i in range(2,n+1):
        res += "0"
    print(res)
    sys.exit(0)
i=0
lst = {}
f = 0
while i < m: 
    s,c = map(int, input().split())
    #先頭が0のケース
    if c == 0 and s == 1 and n >= 2:
        f = 1
    if s not in lst:
        lst[s]=c
    #key重複のときはエラー
    elif c != lst[s]:
        f = 1
    i+=1

if f == 1:
    print(-1)
    sys.exit(0)
    
res = ""
for i in range(1,n+1):
    if i in lst:
        res += str(lst[i])
    else:
        if i == 1:
            res += "1"
        else:
            res += "0"
print(res)


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long A, long long V, long long B, long long W, long long T){
    bool valid = abs(A - B) - T * (V - W) <= 0;
    cout << (valid ? "YES" : "NO") << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long A;
    scanf("%lld",&A);
    long long V;
    scanf("%lld",&V);
    long long B;
    scanf("%lld",&B);
    long long W;
    scanf("%lld",&W);
    long long T;
    scanf("%lld",&T);
    solve(A, V, B, W, T);
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

int main() {

	int N;

	scanf("%d",&N);

	if (N % 2 == 0) { printf("%lf\n",1.0/2.0); }
	else { 
		int child = (N / 2);
		child++;
		printf("%lf\n",(double)child/(double)N); }

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<cstring>
#include<string>
#define MAX_N 100000
#define MAX_M 100000
using namespace std;

typedef long long ll;
ll H[MAX_N];
vector<ll> v[MAX_N];
ll M,N;
ll good;

void solve()
{
    
    good = 0;
    for(ll i=0;i<N;i++){
        ll height = 0;
        for(ll j=0;j<v[i].size();j++){
            height = max(H[v[i][j]], height);
        }
        if(height < H[i] || v[i].size() == 0 ){
            good++;
        }
    }
    cout << good << endl;
}

int main()
{
    ll a, b;
    cin >> N >> M;
    for(ll i=0;i<N;i++){
        cin >> H[i];
    }
    for(ll i=0;i<M;i++){
        cin >> a >> b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    solve();

    
    return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int answer = 1;
    for(int i = 0; i < N-1; i++) {
        if(S.at(i) != S.at(i+1)) {
            answer++;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <vector>

int main()
{
    int n, q;
    std::cin >> n >> q;
    std::vector<std::stack<int>> st(n);

    int m ,t, x;
    for (int i = 0; i < q; i++)
    {
        std::cin >> m>>t;
        if (m == 0)
        {
            std::cin >> x;
            st[t].push(x);
        }
        else if (m == 1)
        {
            if (st[t].size() > 0)
            {
                std::cout << st[t].top() << std::endl;
            }
        }
        else if (m == 2)
        {
            if (st[t].size() > 0)
            {
                st[t].pop();
            }
        }
    }
}




Measured memory_bytes: 4396
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }
    sort(All(A));
    reverse(All(A));
    using pii = pair<int, int>;
    vector<pii> ope;
    ll now = 0;
    if(A[1] > 0) {
        now = A[N - 1];
        ope.push_back(make_pair(A[0], 0));
    } else {
        now = A[0];
        ope.push_back(make_pair(A[N - 1], 0));
    }
    for(int i = 1; i < N - 1; i++) {
        if(A[i] > 0 && (A[i + 1] <= 0 || i + 1 == N - 1))
            ope.push_back(make_pair(A[i], 1));
        else
            ope.push_back(make_pair(A[i], 0));
    }
    vector<pii> res;
    rep(i, ope.size()) {
        if(ope[i].second == 0) {
            res.push_back(make_pair(now, ope[i].first));
            now = now - ope[i].first;
        } else {
            res.push_back(make_pair(ope[i].first, now));
            now = ope[i].first - now;
        }
    }

    cout << now << endl;
    rep(i, res.size()) { cout << res[i].first << " " << res[i].second << endl; }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    if(n==m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
// editorial
#include<iostream>
#include<numeric>
#include<map>
#include<vector>
#include<set>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    map<pair<ll,ll>,int> cnt;
    for(int i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        if(a==0){
            if(b==0){
                ans++;
            }else{
                cnt[{0,1}]++;
            }
            continue;
        }else if(b==0){
            cnt[{-1,0}]++;
            continue;
        }
        ll g = gcd(abs(a), abs(b));
        a /= g, b /= g;
        if(b<0) a*=-1, b*=-1;
        cnt[{a,b}]++;
    }
    vector<ll> two(n+1,1);
    for(int i = 1; i <= n; i++) two[i] = two[i-1]*2%mod;
    set<pair<ll,ll>> done;
    ll add = 1;
    for(auto x : cnt){
        pair<ll,ll> p = x.first;
        if(done.count(p))   continue;
        done.insert(p);
        pair<ll,ll> dp = {-p.second, p.first};
        if(dp.second < 0)   dp.first *= -1, dp.second *= -1;
        if(cnt.count(dp))   done.insert(dp);
        ll a = x.second;
        ll b = cnt.count(dp) ? cnt[dp] : 0;
        ll tmp = (two[a]+two[b]-1+mod)%mod;
        add *= tmp;
        add %= mod;
    }
    add = (add-1+mod)%mod;
    ans += add;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 29776
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;
    int sum = T;
    vector<int> t(N);
    for (int i = 0; i < N; i++){
        cin >> t[i];
    }

    for (int i = 1; i < N; i++){
        int next = t[i] - t[i - 1];
        sum += min(T, next);
    }
    cout << sum << endl;

}

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

int main(){
	int n, a = 0, b = 0, c = 0, ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (a > b&&b > c && i >= 2) {
			ans++;
		}
		else if (a < b && b < c && i>=2) {
			ans++;
		}
		c = b;
		b = a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
use std::io::*;
use std::cmp;
use std::collections::HashMap;


fn main() {
    let (N, S, W, E) = (0, 1, 2, 3);
    let mut buf: String = String::new();
    stdin().read_line(&mut buf);
    buf = buf.trim().to_string();

    let mut coll: HashMap<char, i32> = HashMap::new();

    for c in buf.chars() {
        *coll.entry(c).or_insert(0) += 1
    }
   
    let v = vec!['N', 'S', 'W', 'E'];
    let mut res = vec![0; 4];
    
    for (i, c) in v.iter().enumerate() {
        res[i] = match coll.get(c) {
            Some(n) => *n,
            None => 0
        };
    }

    let cond = cmp::min(res[N], res[S]) == 0 && cmp::max(res[N], res[S]) != 0 || cmp::min(res[W], res[E]) == 0 && cmp::max(res[W], res[E]) != 0;

    if cond {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), e = 0, no = N, max = Integer.MIN_VALUE, t = 0;
		Map<Integer, Integer> m = new HashMap<Integer, Integer>();
		while (no-->0) {
			e = sc.nextInt();
			m.put(e, m.get(e)==null ? 1 : m.get(e)+1);
			m.put(e-1, m.get(e-1)==null ? 1 : m.get(e-1)+1);
			m.put(e+1, m.get(e+1)==null ? 1 : m.get(e+1)+1);
		}
		for (int d : m.keySet()) if (m.get(d)>max) max = m.get(d);
		System.out.println(max);
		sc.close();		
	}

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

}

Measured memory_bytes: 63956
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int> > e(N);
  
  for (int i = 0; i < N-1; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    e[b].push_back(a);
    e[a].push_back(b);
  }

  queue<int> que;
  que.push(0);
  vector<int> c(N,0);
  vector<int> ans(N,-1);

  for (int i = 0; i < Q; i++){
    int p, x;
    cin >> p >> x;
    c[p-1] += x;
  }

  while(!que.empty()){
    int a=que.front();
    que.pop();
    for(int b:e[a]){
      if(ans[b]!=-1) continue;
      que.push(b);
      c[b]+=c[a]; 
      }
      ans[a]++;
  }

  for (int i = 0; i < N; i++){
    printf("%d ", c[i]);
  }
  printf("\n");
  
}


Measured memory_bytes: 17376
#include<stdio.h>
int main(void)
{
    int i,j,s,n,t[100000],m,p[100],x[100000];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&t[i]);
    scanf("%d",&m);
    for(i=1;i<=m;i++)
        scanf("%d%d",&p[i],&x[i]);
    for(i=1;i<=m;i++){
        s=0;
        for(j=1;j<=n;j++){
            if(p[i]==j)
                s+=x[i];
            else 
                s+=t[j];
        }
        printf("%d\n",s);
    }
    return 0;
}

Measured memory_bytes: 1720
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	string s; cin >> s;
	vector<vector<LL>> dp(2, vector<LL>(s.size()));

	dp[0][0] = 2;
	dp[1][0] = 1;

	for (int i = 1; i < s.size(); i++) {
		
		if (s[i] == '1') {
			//0,1 1,0の2個を置くとぴったりを維持
			dp[0][i] += dp[0][i - 1] * 2;
			dp[0][i] = (dp[0][i] + MOD) %MOD;

			//0,0を置いて、ぴったりから未満へ
			dp[1][i] += dp[0][i-1];
			dp[1][i] = (dp[1][i] + MOD) % MOD;
			
			//未満から未満は1,1以外の3つをおける
			dp[1][i] += dp[1][i-1]*3;
			dp[1][i] = (dp[1][i] + MOD) % MOD;
		}

		if (s[i] == '0') {

			//0,0をおくしかない
			dp[0][i] += dp[0][i-1];
			dp[0][i] = (dp[0][i] + MOD) % MOD;

			//未満は1,1以外の3つを自由における
			dp[1][i] += dp[1][i-1] * 3;
			dp[1][i] = (dp[1][i] + MOD) % MOD;
		}
		
	}

	//MODを取り忘れるな！！！
	cout << (dp[0][s.size()-1] + dp[1][s.size()-1])%MOD<< endl;

	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define mod 10000000009
#define pb push_back
ll power(ll a,ll b){
    ll res=1ll;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(n<k) return 0;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i));
        pro/=(i+1);
    }
    return (pro);
}
vector<ll> prime;
void seive(){
    vector<bool > isprime(2000001,true);
    for(int i=2;i*i<=2000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=2000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
void swap(ll *a,ll *b) {
    ll temp=*a;
    *a=*b;
    *b=temp;
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    string str;
    cin>>str;
    ll n=str.size();
    if(n%2==0) {
        cout<<"No";
        return 0;
    }
    string rstr=str;
    reverse(rstr.begin(),rstr.end());
    if(rstr!=str) {
        cout<<"No";
        return 0;
    }
    
    string str1=str.substr(0,(n-1)/2);
    string str2=str.substr((n+3)/2-1);
    // cout<<str1<<" "<<str2<<endl;
    string rstr1=str1;
    string rstr2=str2;
    reverse(rstr1.begin(),rstr1.end());
    reverse(rstr2.begin(),rstr2.end());
    if(rstr1==str1 && rstr2==str2) {
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0; 
}


Measured memory_bytes: 256
<?php

class out {
    public static function println($str = "") {
        echo ($str) . PHP_EOL;
    }
}


$num = trim(fgets(STDIN));
$array1 = str_split($num);

$ans = 0;
foreach ($array1 as $value) {
    // code...
    $ans += intval($value);
}

out::println($ans);

  
?>

Measured memory_bytes: 3828
n,k=list(map(int,input().split()))
alst=list(map(int,input().split()))

ok=max(alst)
ng=0

while abs(ok-ng)>1:
    cen=(ok+ng)//2

    cnt=0

    for a in alst:
        cnt+=(a+cen-1)//cen-1

    if cnt<=k:
        ok=cen
    else:
        ng=cen

print(ok)

Measured memory_bytes: 104096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		sc.close();

		int p = 0;
		int m = 0;

		char ch[] = new char[S.length()];

		for (int i = 0; i < S.length(); i++) {
			ch[i] = S.charAt(i);

			if (ch[i] == '+') {
				p++;
			} else if (ch[i] == '-') {
				m++;
			}
		}
		System.out.print(p-m);
	}
}

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

string calc(int n){
    if(n == 0) return "0";
    if(n == 1) return "1";
    string s;
    int r = abs(n)%2;
    char c = '0'+r;
    s = calc((n-r)/(-2))+c;
    return s;
}

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

    string ans = calc(n);
    cout << ans << endl;
}

Measured memory_bytes: 256