akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;

int main(){
	int a[3][3], d[3][3];
	rep(i,3) rep(j,3) cin >> a[i][j];
	int n;
	cin >> n;
	rep(ni,n) {
		int x; cin >> x;
		rep(i,3) rep(j,3) if (a[i][j] == x) d[i][j] = 1;
	}
	bool ans = false;
	rep(i,3) {
		int cut = 0;
		rep(j,3) cut += d[i][j];
		if (cut == 3) ans = true;
	}
	rep(i,3) {
		int cut = 0;
		rep(j,3) cut += d[j][i];
		if (cut == 3) ans = true;
	}
	{	
		int cut = 0;
		rep(i,3) cut += d[i][i];
		if (cut == 3) ans = true;
	}
	{
		int cut = 0;
		rep(i,3) cut += d[i][2-i];
		if (cut == 3) ans = true;
	}

	puts(ans?"Yes":"No");

	return 0;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }



int main()
{
	int n, w = 0, ans = 0;
	string c;

	cin >> n >> c;
	for (int i = 0; i < n; i++)
		if (c[i] == 'W')
			w++;
	for (int i = 0; i < n - w; i++)
		if (c[i] == 'W')
			ans++;
	cout << ans << endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;

#define MOD (long)(1e9 + 7)

long long modPow(int x, int n){
  if(n == 0) return 1;
  if(n % 2 == 0) {
    long long sqrtX = modPow(x,n/2);
    return sqrtX * sqrtX % MOD ;
  }else{
    return x * modPow(x,n-1) % MOD;
  }
}
ll kaizyouArray[300000];
long long kaizyou(long long x){
  return kaizyouArray[x];
}

long long modCombi(long long a, long long b){
  if(b > a/2) return modCombi(a,a-b);
  return ((kaizyou(a) * modPow(kaizyou(b),MOD - 2)) % MOD)* modPow(kaizyou(a-b),MOD - 2) % MOD;
}

int main(){
  ll H,W,A,B;
  cin >> H >> W >> A >> B;
  kaizyouArray[0] = 1; kaizyouArray[1] = 1;
  FOR(i,2,300000) kaizyouArray[i] = (kaizyouArray[i-1]*i) % MOD;
  ll ans = 0;
  rep(i,H-A){
    ans += modCombi(B+i-1,B-1) * modCombi((H-i+W-B-2),(H-i-1));
    ans = ans % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
open Scanf
open Printf

let rint () = scanf " %d" (fun x -> x)
let stoa s = Array.init (String.length s) (String.get s)
let atos a = String.init (Array.length a) (Array.get a)

let () =
  let a = rint() and b = rint() in
  printf "%d\n" (max (a + b) (max (a - b) (a * b)))

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long


int dp[110][4][4][4];
const int A = 0, G = 1, C = 2, T = 3;
bool ng(int x1, int x2, int x3, int x4) {
    int x[4] = {x1, x2, x3, x4};
    rep(i, 4) {
        if (x[0] == A && x[1] == G && x[2] == C) return true;
        if (x[1] == A && x[2] == G && x[3] == C) return true;
        if (i != 0)
            swap(x[i - 1], x[i]);
        if (i != 3)
            swap(x[i], x[i + 1]);
    }
    return false;

}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, 4) rep(j, 4) rep(k, 4) {
        if (ng(i, j, k, -1)) {continue;}
        dp[3][i][j][k] = 1;
    }
    REP(i, 3, N - 1) rep(j, 4) rep(k, 4) rep(l, 4) rep(m, 4) {
        if (ng(j, k, l, m)) continue;
        dp[i + 1][k][l][m] = (dp[i + 1][k][l][m] + dp[i][j][k][l]) % mod;
    }
    int ans = 0;
    rep(i, 4) rep(j, 4) rep(k, 4) ans = (ans + dp[N][i][j][k]) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<unordered_map>
#include<string>
#define LL long long
#define li i<<1
#define ri i<<1|1
using namespace std;
inline LL read()
{
    char c=getchar();LL x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
LL a,b,c,k;
int main()
{
	a=read();
	b=read();
	c=read();
	k=read();
	int times=0;
	while(b<=a){
		++times;
		b*=2;
	}
	while(c<=b){
		++times;
		c*=2;
	}
//	printf("%d\n",times);
	if(times<=k)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    string s,t="CODEFESTIVAL2016";
    int cnt=0;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])
            cnt+=1;
    }
    cout<<cnt<<"\n";
}

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

using namespace std;

const int maxn = 100;
int n, k, v[maxn];

void Enter()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> v[i];
}

void Solve()
{
    int res = -1, a[maxn];
    for (int i = 0; i <= k; i++)
        for (int j = 0; j <= k - i; j++)
            {
                int spt = 0;
                memset(a, 0, sizeof(a));
                if (i + j > n) continue;
                for (int l = 1; l <= i; l++)
                    a[++spt] = v[l];
                for (int l = n; l >= n - j + 1; l--)
                    a[++spt] = v[l];
                sort(a + 1, a + spt + 1);
                int s = 0;
                for (int i = 1; i <= spt; i++)
                    s += a[i];
                for (int l = 0; l <= k - i - j; l++)
                {
                    s -= a[l];
                    res = max(res, s);
                }
            }
    cout << res;
}

int main()
{
    Enter();
    Solve();
    return 0;
}


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

int main () {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (x - r < 0 || y - r < 0 || x + r > W || y + r > H) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
string s,t;
cin>>s>>t;
bool a=true;

rep(i,s.size()){
    if(s[i]!=t[i])a=false;
}

if(a)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

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

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

    tmp2 = a;
    a =c;
    c = tmp2;

    cout << a << " " << b << " " << c;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
k = [list(map(int,input().split())) for _ in range(N)]
ans = 0

for i in range(1,M+1):
    isLike = True
    for j in k:
        if not i in j[1:]:
            isLike = False
    if isLike:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int a,b,ans=0;
  while(scanf("%d",&a)!=EOF){
    cin >> b;
    ans = 0;
    a += b;
    while(a >= 1){
      a /= 10;
      ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1240
#include<iostream>
using namespace std;
#include<string>
#include<stdio.h>

#define A 1995455101 // large prime number.
#define B 1995455447 // large prime number, bigger than A.

int main()
{
    string T; cin >> T; int len_T = T.size();
    string P; cin >> P; int len_P = P.size();
    long long *has_T, *has_P;
    has_T = new long long [len_T];
    has_P = new long long [len_P];

    long long h = 0; int i;  // hash coding.
    // has_T[i] = (T[0]A^{i-1} + T[1]A^{i-2} + ... + T[i-1]A + T[i]) % B.
    for(i = 0; i < len_T; i++){ h = (h * A + T[i]) % B; has_T[i] = h; }
    h = 0;
    // has_P[i] = (P[0]A^{i-1} + P[1]A^{i-2} + ... + P[i-1]A + P[i]) % B.
    for(i = 0; i < len_P; i++){ h = (h * A + P[i]) % B; has_P[i] = h; }

    // last_has = (P[0]A^{len_P-1} + P[1]A^{len_P-2} + ... + P[len_P-1]) % B.
    long long last_has = has_P[len_P - 1];
    // A^{len_P} Mod B.
    long long power, x, y, z;
    x = A, y = len_P, z = 1;
    for( ; y; y /= 2){
        if((y & 1) != 0){ z = (z * x) % B; }
        x = (x * x) % B;
    }
    power = z;

    for(i = len_P - 1; i < len_T; i++){
        if(has_T[i] == ((i >= len_P ? has_T[i - len_P] : 0) * power + last_has) % B){
			printf("%d\n", i - len_P + 1);
        }
    }
    return 0;
}

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

int main(){

    string S;
    cin >> S;
    int size,count;
    size = S.size();
    count = 0;
    for(int i = 0;i<S.size();i++){
        if(S[i]=='x'){
            count ++;
        }
        if(count >=8){
            
            cout << "NO" <<endl;
            return 0;
        }
    }
    cout <<"YES"<<endl;
    
}

Measured memory_bytes: 256
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()
    };

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

fn main() {
    input! {
        a: i32, b: i32
    }

    let result = (1..1250).filter(|&x| ((x as f32)*0.08).floor() as i32 == a && ((x as f32)*0.1).floor() as i32 == b).min().unwrap_or(-1);

    println!("{}", result);
}



Measured memory_bytes: 4352
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
var n = parseInt(input.shift(), 10);
var nums = input.shift().split(' ').map(Number);
 
for (var i = 0; i < nums.length; i += 1) {
  var v = nums[i];
  var j = i - 1;
  while (j >= 0 && nums[j] > v) {
    nums[j + 1] = nums[j];
    j -= 1;
  }
  nums[j + 1] = v;
  console.log(nums.join(' '));
}

Measured memory_bytes: 16672
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: x,y,ans

    read*, x,y
    ans = 2000000000
    if (y-x >= 0) then
        ans=min(ans,y-x)
    end if

    if (y-(-x) >= 0) then
        ans = min(ans,y-(-x)+1)
    end if

    if ((-y) - x >= 0)then
        ans = min(ans,(-y)-x+1)
    end if

    if ((-y)-(-x) >= 0) then
        ans = min(ans,(-y)-(-x)+2)
    end if

    print'(i0)', ans
end program name

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
check = True
count = 0

while(check):
  for i in range(n-1):
    if a[i] % 2 == 0:
      a[i] = a[i] / 2
    else:
      check = False
      break         
  else:
    count += 1
        
print(count)

Measured memory_bytes: 3060
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int N, X;
	cin >> N >> X;
	int count = 0, now = 0;
	for (int i = 0; i < N; ++i)
	{
		int L;
		cin >> L;
		if (now <= X)
		{
			++count;
			now += L;
		}
	}
	if (now <= X)
	{
		++count;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;
ll a1 , b  , ans , n , m , cnt , c;
string s;
int main(){
    cin >> n;
    cout << 3 * pow(n , 2) << endl;
}



Measured memory_bytes: 256
using Hitachi2020.Questions;
using Hitachi2020.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Hitachi2020.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            s = s.Replace("hi", "");
            yield return s == string.Empty ? "Yes" : "No";
        }
    }
}


namespace Hitachi2020
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Hitachi2020.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Hitachi2020.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13140
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int e[100009],k;
typedef pair<int,int> P;
deque<P>q;
int main(){scanf("%d",&k);
    memset(e,0,sizeof(e));q.push_back(make_pair(1,1));
    while(!q.empty()){P x=q.front();q.pop_front();
     if(e[x.first])continue;e[x.first]=1;
     if(x.first==0){printf("%d\n",x.second);break;}
     q.push_front(make_pair(x.first*10%k,x.second));
     q.push_back(make_pair((x.first+1)%k,x.second+1));
    }return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <assert.h>
#include <string>
#include <cmath>
#include <algorithm>

int main(){
    std::string S;
    std::cin >> S;
    int32_t evenB = 0, evenW = 0, oddB = 0, oddW = 0;
    for(int32_t i = 0; i < (int32_t)S.size(); i++){
        if(i % 2 == 0){
            if(S[i] == '0'){
                evenB++;
            }
            else{
                evenW++;
            }
        }
        else{
            if(S[i] == '0'){
                oddB++;
            }
            else{
                oddW++;
            }
        }
    }

    int32_t res = std::min(evenB + oddW, evenW + oddB);
    std::cout << res;

    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    int N,x;
    cin >> N >> x;

    if(x == 2 * N - 1 || x == 1){
        cout << "No" << endl;
        return 0;
    }

    set<int> S;
    REP(i,1,2 * N){
        S.insert(i);
    }

    REP(i,-1,2){
        S.erase(x+i);
    }

    cout << "Yes" << endl;
    REP(i,0,N-2){
        cout << *S.lower_bound(i) << endl;
        S.erase(S.lower_bound(i));
    }
    REP(i,-1,2){
        cout << x + i << endl;
    }
    REP(i,0,N-2){
        cout << *S.lower_bound(i) << endl;
        S.erase(S.lower_bound(i));
    }


    return 0;
}


Measured memory_bytes: 10880
#include<queue>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int P[200011];
int V[200011];
bool use[200011];

int getP(int v) {
    if (!use[P[v]]) return P[v];
    return P[v] = getP(P[v]);
}

struct Data {
    LL z, o;
    int i;

    Data() {
	z = o = i = 0;
    }

    bool operator!=(const Data &y) const {
	return z != y.z || o != y.o || i != y.i;
    }

    bool operator<(const Data &y) const {
	// return z/o < y.z/y.o;
	if (o == 0) return false;
	if (y.o == 0) return true;
	return z * y.o < o * y.z;
    }
} D[200011];

void MAIN() {
    scanf("%d", &N);
    for (int i=1; i<N; i++) scanf("%d", P+i), P[i]--;
    REP (i, N) scanf("%d", V+i);

    for (int v=N; v--;) {
	if (V[v] == 0) {
	    D[v].z++;
	} else {
	    D[v].o++;
	}
	D[v].i = v;
    }

    priority_queue<Data> Q(D+1, D+N);
    LL ans = 0;
    while (!Q.empty()) {
	Data d = Q.top(); Q.pop();
	if (use[d.i] || d != D[d.i]) continue;
	int p = getP(d.i);
	ans += D[p].o * d.z;
	use[d.i] = true;
	D[p].z += d.z;
	D[p].o += d.o;
	if (p) Q.push(D[p]);
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 11392
#include <stdio.h>
#define num_element 256
int main(void)
{
	int i,n,m;
	char array[num_element];
	char a[2];
	char b[2];
	char input[2];
	while(1)
	{
		for(i=0;i<num_element;i++)
		{
			array[i] = i;
		}
		scanf("%d",&n);
		if(n == 0)return 0;
		for(i=0;i<n;i++)
		{
			scanf("%s %s",a,b);
			array[a[0]] = b[0];
		}
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%s",input);
			printf("%c",array[input[0]]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;

// ax + by = c  ->  adx = cd - dby
// dx + ey = f  ->  adx = fa - aey

// (db - ae)y = cd - fa
// y = (cd - fa) / (db - ae)
// x = (c - by) / a

int main(){
    int a,b,c,d,e,f;
    while(cin >> a >> b >> c >> d >> e >> f){
        double y = 1.0 * (c*d - f*a) / (d*b - a*e);
        double x = (c - b * y) / a;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 1192
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
ans=0
dic={'r':'p','s':'r','p':'s'}
score={'r':R,'s':S,'p':P}
past=[]
for i in range(len(T)):
    if i>=K:
        if dic[T[i]]==past[i-K]:
            past.append('0')
            continue
        else:
            ans+=score[dic[T[i]]]
            past.append(dic[T[i]])
    else:
        ans+=score[dic[T[i]]]
        past.append(dic[T[i]])
print(ans)

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

int main(void)
{
    int n;
    long long min, max, total;

    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    min = max = total = a[0];
    for (int i = 1; i < n; i++)
    {
        if (min > a[i])
            min = a[i];
        else if (max < a[i])
            max = a[i];

        total += a[i];
    }
        cout << min << " " << max << " " << total << endl;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
struct input_t{template<class T>operator T(){T t;std::cin>>t;return t;}}input;
lint mod=2019;/*{{{*/
lint inverse(lint x){
    assert(x%mod);
    lint y=1,u=mod,v=0;
    while(x){lint q=u/x;u-=q*x;std::swap(u,x);v-=q*y;std::swap(v,y);}
    assert(x==0&&std::abs(u)==1&&std::abs(y)==mod&&std::abs(v)<mod);
    return v<0?v+mod:v;
}
lint normalized(lint x){if(x<=-mod||mod<=x)x%=mod;if(x<0)x+=mod;return x;}
struct mint{
    lint value;
    mint()=default;
    mint(lint x):value(normalized(x)){}
};
std::ostream&operator<<(std::ostream&os,mint x){return os<<x.value;}
mint operator+(mint x,mint y){lint z=x.value+y.value;if(mod<=z)z-=mod;return mint{z};}
mint operator-(mint x,mint y){lint z=x.value-y.value;if(z<0)z+=mod;return mint{z};}
mint operator*(mint x,mint y){return mint{x.value*y.value%mod};}
mint operator/(mint x,mint y){return mint{x.value*inverse(y.value)%mod};}
mint&operator+=(mint&x,mint y){return x=x+y;}
mint&operator-=(mint&x,mint y){return x=x-y;}
mint&operator*=(mint&x,mint y){return x=x*y;}
mint&operator/=(mint&x,mint y){return x=x/y;}
bool operator==(mint x,mint y){return x.value==y.value;}
bool operator!=(mint x,mint y){return x.value!=y.value;}
mint power(mint x,lint y){mint z=1;for(;y;y>>=1){if(y&1)z*=x;x*=x;}return z;}/*}}}*/
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    std::string s=input;
    lint n=s.length();
    std::reverse(ALL(s));
    std::vector<mint>a(n+1);
    mint pow10=1;
    for(lint i=0;i<n;i++){
        mint x=s.at(i)-'0';
        a.at(i+1)=a.at(i)+pow10*x;
        pow10*=10;
    }
    std::map<lint,lint>map;
    for(mint x:a)map[x.value]++;
    lint ans=0;
    for(auto[_,m]:map){
        ans+=m*(m-1)/2;
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
const int maxn = 220;
int a[maxn],b[maxn],c[maxn];
int ans,n,k;
int x,y;
int Ma,Mb;
int inf=2000000;
int dp[50][500][500];
int main()
{
    cin>>n>>Ma>>Mb;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    for(int i=0;i<=40;i++)
    {
        for(int j=0;j<=400;j++)
        {
            for(int z=0;z<=400;z++)
            {
                dp[i][j][z]=inf;
            }
        }
    }
    dp[0][0][0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=400;j++)
        {
            for(int z=0;z<=400;z++)
            {
                if(dp[i][j][z]==inf) continue;
                dp[i+1][j][z]=min(dp[i][j][z],dp[i+1][j][z]);
                dp[i+1][j+a[i]][z+b[i]]=min(dp[i+1][j+a[i]][z+b[i]],dp[i][j][z]+c[i]);
            }
        }
    }
    int Minx=inf;
    for(int i=1;i<=400;i++)
    {
        for(int j=1;j<=400;j++)
        {
            if(i*Mb==j*Ma)
            {
                Minx=min(Minx,dp[n][i][j]);
            }
        }
    }
    if(Minx==inf)
    {
        cout<<"-1";
    }
    else
    {
        cout<<Minx;
    }
    return 0;
}

Measured memory_bytes: 32512
h, w, k = gets.split.map(&:to_i)
rows = Array.new(h){gets.chomp.bytes.map{|c| (c == '#'.ord) ? 1 : 0}}
cnt = 0
[0, 1].repeated_permutation(h) do |x|
  m = []
  x.each_with_index do |y, i|
    if y == 0
      m << rows[i].dup
    else
      m << [0] * w
    end
  end
  [0, 1].repeated_permutation(w) do |u|
    mc = []
    u.each_with_index do |v, l|
      if v == 0
        mc << m.transpose[l]        
      end
    end
    cnt += 1 if mc.to_a.flatten.sum == k
  end
end
puts cnt

Measured memory_bytes: 14432
#include<bits/stdc++.h>
#define inf 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int a, va, b, vb, t;
    scanf("%d%d",&a,&va);
    scanf("%d%d",&b,&vb);
    scanf("%d",&t);
    ll z=((ll)(va-vb))*t;
    if(z<abs(a-b))
    {
        printf("NO\n");
    }
    else
    {
        printf("YES\n");
    }
    return 0;
}



Measured memory_bytes: 3688
# -*- coding: utf-8 -*-
# B: Shift Only
# 標準入力の取得
N = int(input())
A_list = list(map(int, input().split()))

# 操作回数の算出
operation_count = 0 # 操作回数
can_operate = True # 操作可能であるかどうか
while can_operate:
    operation_count += 1
    # リスト内の各要素に操作を実施
    for i in range(len(A_list)):
        remainder = A_list[i] % 2
        if remainder == 0:
            # 偶数の場合、要素を更新
            A_list[i] /= 2
        else:
            # 奇数の場合、操作不可能とし、操作回数を1引いておく
            can_operate = False
            operation_count -= 1
            break

print(operation_count)

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

const int MAXN = 300000;

int segTree[MAXN * 4];

void build_tree(int pos, int low, int high) {
	segTree[pos] = 0;
	if (low == high) {
		return;
	}
	int mid = (low + high) / 2;
	build_tree(pos * 2 + 1, low, mid);
	build_tree(pos * 2 + 2, mid + 1, high);
}

void update(int pos, int low, int high, int qpos, int value) {
	if (low == high) {
		segTree[pos] = value;
		return;
	}
	int mid = (low + high) / 2;
	if (mid >= qpos) {
		update(pos * 2 + 1, low, mid, qpos, value);
	} else {
		update(pos * 2 + 2, mid + 1, high, qpos, value);
	}
	segTree[pos] = max(segTree[pos * 2 + 1], segTree[pos * 2 + 2]);
}

int query(int pos, int low, int high, int qlow, int qhigh) {
	if (qlow > high || qhigh < low) {
		return 0;
	}
	if (qlow <= low && qhigh >= high) {
		return segTree[pos];
	}
	int mid = (low + high) / 2;
	return max(query(pos * 2 + 1, low, mid, qlow, qhigh), query(pos * 2 + 2, mid + 1, high, qlow, qhigh));
}

int arr[MAXN];
int sorted[MAXN];
int M;

int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> arr[i];
	}
	memcpy(sorted, arr, sizeof(sorted));
	sort(sorted, sorted + N);
	M = unique(sorted, sorted + N) - sorted;
	build_tree(0, 0, M - 1);
	int res = 0;
	for (int i = 0; i < N; i++) {
		int loc = lower_bound(sorted, sorted + M, arr[i]) - sorted;
		int low = lower_bound(sorted, sorted + M, arr[i] - K) - sorted;
		int high = upper_bound(sorted, sorted + M, arr[i] + K) - sorted - 1;
		int value = query(0, 0, M - 1, low, high) + 1;
		res = max(res, value);
		update(0, 0, M - 1, loc, value);
	}
	cout << res << endl;
}

Measured memory_bytes: 7936
from collections import deque
import sys
input = sys.stdin.readline
s = str(input().rstrip())
ans = deque(list(s))

f = True
q = int(input())
for i in range(q):
    q = list(map(str, input().split()))
    if int(q[0]) == 1:
        f = not f
    else:
        f_i = int(q[1])
        if (f_i == 1) ^ f:
            ans.append(q[2])
        else:
            ans.appendleft(q[2])
ans = "".join(list(ans))
if not f:
    ans = ans[::-1]
print(ans)


Measured memory_bytes: 8676
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[201];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    char c;
    string s,s1;
    priority_queue<int> pq;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='Y') sum=1;
    }
    if(sum==1) cout<<"Four";
    else cout<<"Three";
    return 0;
}



Measured memory_bytes: 256
/*
 * じょえチャンネルを応援します！
 * https://www.youtube.com/watch?v=gPFr7q7eLL8
 */
void main() {
	auto ip = readAs!(int[]), N = ip[0], R = ip[1];
	if(N >= 10) writeln(R);
	else writeln(R + (100 * (10 - N)));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
def spaceinput():
    return list(map(int,input().split(" ")))

a,b,c,d,e,f=spaceinput()


smax=0
wmax=100*a
maxnoudo=0

for na in range(int(f/(100*a))+1):
    for nb in range(int(f/(100*b))+1):
        for nc in range(int(f/c)+2):
            for nd in range(int(f/d)+2):
                W=na*100*a+nb*100*b
                S=nc*c+nd*d


                if W+S>f:
                    break

                if W+S==0:
                    continue

                noudo=S/(W+S)
                #print(noudo,S,W,f,e)
                #print("aaa")
                if noudo>e/(100+e):
                    break

                #print(na,nb,nc,nd)
                if maxnoudo<noudo:
                    maxnoudo=noudo
                    smax=S
                    wmax=W
                    #input()


print(smax+wmax,smax)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define db(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define rep(i,b)for(auto i=(0);i<(b);++i)
#define fo(i,a,b)for(auto i=(a);i<=(b);++i)
#define ford(i,a,b)for(auto i=(a);i>=(b);--i)
#define all(x) (x).begin(),(x).end()
#define vv vector
#define pb push_back
template<typename X>void MA(X&a,X b){a=max(a,b);}template<typename X>void MI(X&a,X b){a=min(a,b);}
template<typename X>void clr(X&x,int a){memset(x,a,sizeof(a));};typedef long long ll;typedef long double ld;
typedef array<int,2>i2;typedef vv<int>vi;int cond=0,multi=0,gcj=0;

struct solver_t;solver_t *solver;
struct solver_t{


  void solve(){
    int N;cin>>N;
    cout<<24+24-N<<"\n";
  }
};

void gen(){}
void brute(){}
int main(int argc,char** argv){
  fo(i,1,argc-1)if(argv[i]==string("q"))cond=1<<30;
  fo(i,1,argc-1)if(argv[i]==string("gen")){gen();exit(0);}
  fo(i,1,argc-1)if(argv[i]==string("brute")){brute();exit(0);}
  ios::sync_with_stdio(false),cin.tie(0);
  cout.setf(ios::fixed),cout.precision(10);int t;if(multi||gcj)cin>>t;else t=1;
  fo(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    solver = new solver_t();
    solver->solve();
  }return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    S = SI()
    if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
        ans = 'Bad'
    else:
        ans = 'Good'
    return ans

print(main())

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  cin >> s;
  bool Nf = false,Sf = false,Wf = false,Ef = false;
  rep(i,s.size()){
    switch(s.at(i)){
      case 'N':
        Nf = true;
        break;
      case 'S':
        Sf = true;
        break;
      case 'W':
        Wf = true;
        break;
      case 'E':
        Ef = true;
        break;
    }
  }
  if((Nf==Sf)&&(Wf==Ef)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
      
}

Measured memory_bytes: 256
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    # N = int(input())
    N,M = map(int, input().split())
    XS = list(map(int, input().split()))
    XS.sort()
    intervals = [0]*(M-1)
    for i in range(M-1):
        intervals[i] = XS[i+1]-XS[i]
    intervals.sort(reverse=True)
    print(XS[M-1]-XS[0]-sum(intervals[:min(M-1,N-1)]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14964
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;
#define INF 1000000000000
#define NOD 1000000007
#define PI 3.141592653589793238462643

int main() {
    int n;
    ll s=0;
    cin >> n;
    vector<int> data(n*3);
    REP(i, n*3) cin >> data.at(i);
    ASORT(data);
    for(int i=n*3-2; i>=n; i-=2) s += data.at(i);
    cout << s <<endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    //mod2で考えてよい
    //まず各行について、左から見て行って1であれば右に移動、
    //その結果0になればその行の次の1を探す
    //その結果1のままならさらに右に移動
    //これにより最も右列以外全部0になる
    //最後に右列を上から同じように見ていく
    //これで全部0or一個だけ1になってこれが最大
    int H,W;
    cin>>H>>W;
    vector<vector<int>> a(H,vector<int>(W,0));
    rep(i,H){
        rep(j,W){
            cin>>a.at(i).at(j);
            a.at(i).at(j)=a.at(i).at(j)%2;
        }
    }
    vector<pair<int,int>> mae;//移動前座標
    vector<pair<int,int>> ato;//移動後座標
    rep(i,H){
        //各行について確認
        rep(j,W-1){
            if(a.at(i).at(j)%2==1){
                mae.push_back({i+1,j+1});
                ato.push_back({i+1,j+2});
                //移動
                a.at(i).at(j)=0;
                a.at(i).at(j+1)++;
            }else{
                continue;
            }
        }
    }
    //右列について確認
    rep(i,H-1){
        if(a.at(i).at(W-1)%2==1){
            mae.push_back({i+1,W});
            ato.push_back({i+2,W});
            //移動
            a.at(i).at(W-1)=0;
            a.at(i+1).at(W-1)++;
        }else{
            continue;
        }
    }
    //答えを出力
    int N=0;
    N=ato.size();
    cout << N << endl;

    rep(i,N){
        cout << mae.at(i).first << " " << mae.at(i).second << " " << ato.at(i).first << " " << ato.at(i).second << endl;
    }


    return 0;
}

Measured memory_bytes: 5356
S =input()
del_flag = False
while True:
    if len(S) % 2 == 0 and del_flag == True:
        if S[:len(S)//2] == S[len(S)//2:len(S)]:
            print(len(S))
            exit()
    S = S[:len(S)-1]
    del_flag = True

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int _b=(b),i=(a);i<_b;++i)
#define ROF(i, b, a) for(int _a=(a),i=(b);i>_a;--i)
#define REP(n) for(int _n=(n);_n--;)
#define _1 first
#define _2 second
#define PB(x) push_back(x)
#define SZ(x) int((x).size())
#define ALL(x) (x).begin(), (x).end()
#define MSET(m,v) memset(m,v,sizeof(m))
#define MAX_PQ(T) priority_queue<T>
#define MIN_PQ(T) priority_queue<T,vector<T>,greater<T>>
#define IO(){ios_base::sync_with_stdio(0);cin.tie(0);}
#define cint1(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long int ll; typedef pair<int,int> PII;typedef unsigned long long int ull;
typedef vector<int>VI; typedef vector<ll> VL; typedef vector<PII> VP;
template<class A,class B>inline bool mina(A &x,const B &y){return(y<x)?(x=y,1):0;}
template<class A,class B>inline bool maxa(A &x,const B &y){return(x<y)?(x=y,1):0;}

int D[10] = {0};
int main() {
	IO();
	cint2(N, K);
	REP(K) {
		cint1(a);
		D[a] = 1;
	}
	FOR(i, N, 100000) {
		int a = i;
		int v = 1;
		while(a > 0) {
			int d  = a % 10;
			a /= 10;
			if(D[d]) {
				v = 0;
				break;
			}
		}
		if (v) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
import itertools

N,M = map(int,readline().split())
AB = []
C = []
for _ in range(M):
    AB.append(tuple(int(x) for x in readline().split()))
    C.append(sum(1<<(int(x)-1) for  x in readline().split()))

INF = 10**18
dp = [INF] * (1<<N)
dp[0] = 0

for n,((a,b),c) in itertools.product(range(1<<N),zip(AB,C)):
    m = n|c
    x = dp[n]+a
    if dp[m] > x:
      dp[m] = x
      
answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)


Measured memory_bytes: 3444
#include<stdio.h>
int main()
{
  double W,H,x,y;
  int method;
  scanf("%lf %lf %lf %lf",&W,&H,&x,&y); 
  
  //printf("\nW:%d H:%d x:%d y:%d ",W,H,x,y);
  //printf("WH:%lf W/2:%lf H/2:%lf ",double(W*H),double(W/2),double(H/2));
  //printf("%d",H/2==1.5);
   
  if(x==W/2&&y==H/2)
    method=1;
  else
    method=0;
  
  //printf("meth:%d\n",method);
  
  printf("%lf %d",double(W*H/2),method);
  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(float, sys.stdin.readline().split()))

A, B = input().split()
A = int(A)
B = Decimal(B)

print(math.floor(A * B))

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	int n;
	cin>>n;
	double ans = 0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		ans += 1.0 / a;
	}
	ans = 1 / ans;
	cout << setprecision(12) << fixed << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    double A, B, H, M; cin >> A >> B >> H >> M;
    
    double thetaH = 2.0 * PI * (H / 12.0 + M / (60.0 * 12.0));
    double thetaM = 2.0 * PI * M / 60.0;

    double distance = sqrt(pow(A * sin(thetaH) - B * sin(thetaM), 2) + pow(A * cos(thetaH) - B * cos(thetaM), 2));

    cout << fixed; // 小数点以下の桁数を固定の長さとする．
    cout << setprecision(18) << distance << endl;  // 小数点以下の桁数を指定する（iomanip をインクルード）
    return 0;
}


Measured memory_bytes: 4152
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] c=sc.next().toCharArray();
		
		boolean sh[]=new boolean[n+2];
		
		for(int z=0;z<4;z++){
			Arrays.fill(sh, false);
			sh[0]=(z&1)==0; sh[1]=(z&2)==0;
			for(int i=2;i<n+2;i++){
				sh[i]=sh[i-1]^sh[i-2]^c[(i-1)%n]=='o';
			}
			if(sh[n]==sh[0]&&sh[n+1]==sh[1]){
				put(sh);
				return;
			}
		}
		
		System.out.println(-1);
	}
	
	static void put(boolean[] sh){
		for(int i=0;i<sh.length-2;i++){
			System.out.print(sh[i]?"S":"W");
		}
		System.out.println();
	}
}


Measured memory_bytes: 31668
#include <cstdio>
#include <algorithm>
#define LL long long
#define INF 2000000000
#define maxn 1010
using namespace std;
int n,m;
int k[][2]={{-1,0},{1,0},{0,-1},{0,1}};//L,R,U,D
int border[maxn][maxn][4];//边界
int vis[maxn][maxn],qx[maxn*maxn],qy[maxn*maxn];
LL ans;
struct node{
	int a,b,c;
}f[maxn],g[maxn];
int X[maxn],Y[maxn],XN,YN;
int findX(int v){
	return lower_bound(X,X+XN,v)-X;
}
int findY(int v){
	return lower_bound(Y,Y+YN,v)-Y;
}
void bfs(int xx,int yy){
	int i,h,t,nx,ny,x,y;
	h=t=0;
	qx[t]=xx,qy[t]=yy,t++,vis[xx][yy]=1;
	while(h<t){
		x=qx[h],y=qy[h],h++;
		ans+=(LL)(X[x+1]-X[x])*(Y[y+1]-Y[y]);
		for(i=0;i<4;i++){
			if(border[x][y][i])continue;
			nx=x+k[i][0],ny=y+k[i][1];
			if(nx==0||nx==XN-1||ny==0||ny==YN-1){
				ans=-1;
				return;
			}
			if(vis[nx][ny])continue;
			vis[nx][ny]=1,qx[t]=nx,qy[t]=ny,t++;
		}
	}
}
void init(){
	int i,x,y,r,j;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)scanf("%d%d%d",&f[i].a,&f[i].b,&f[i].c),X[XN++]=f[i].c;
	X[XN++]=-INF,X[XN++]=INF;
	sort(X,X+XN);//自小到大排序
	XN=unique(X,X+XN)-X;//去重
	for(i=0;i<m;i++)scanf("%d%d%d",&g[i].a,&g[i].b,&g[i].c),Y[YN++]=g[i].a;
	Y[YN++]=-INF,Y[YN++]=INF;
	sort(Y,Y+YN);//自小到大排序
	YN=unique(Y,Y+YN)-Y;
	for(i=0;i<n;i++){
		x=findX(f[i].c);
		r=findY(f[i].b);
		if(Y[r]!=f[i].b)r--;
		for(j=findY(f[i].a);j<r;j++)
			border[x-1][j][1]=border[x][j][0]=1;//边界设定
	}
	for(i=0;i<m;i++){
		y=findY(g[i].a);
		r=findX(g[i].c);
		if(X[r]!=g[i].c)r--;
		for(j=findX(g[i].b);j<r;j++)
			border[j][y-1][3]=border[j][y][2]=1;//边界设定
	}
}
int main(){
	init();
	bfs(findX(0)-1,findY(0)-1);
	if(ans==-1)printf("INF\n");
	else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 30684
using System;
using System.Collections.Generic;
using System.Linq;
class P{
    static void Main(){
        string[] s = Console.ReadLine().Split();
        int n = int.Parse(s[0]);
        int m = int.Parse(s[1]);
        int u = m / n;
        for (int i = u;i > 0;i--){
            if (m % i == 0){
                Console.WriteLine(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const int N = 50;
long long bit[N][N];
void add(int x, int y){
    x++;y++;
    for(int i=x;i>0;i-=(i&-i)){
        for(int j=y;j>0;j-=(j&-j)){
            bit[i][j]++;
        }
    }
}
long long  get(int x, int y){
    x++;
    y++;
    int ret = 0;
    for(int i=x;i<N;i+=(i&(-i))){
        for(int j=y;j<N;j+=(j&-j)){
            ret+=bit[i][j];
        }
    }
    return ret;
}
void solve(){
    int n;
    cin>>n;
    long long ans = 0;
    for(int i=1;i<=n;i++){
        long double x;
        cin>>x;
        x*=1e10;
        long long trt =llround( x);
        long long trt2 = trt;
        long long trt5 = trt;
        int c2 =0;
        int c5 =0;
        while(trt2%2==0){
            c2++;
            trt2/=2;
        }
        while(trt5%5==0){
            c5++;
            trt5/=5;
        }
        int nx = 20-c2;
        if(nx<0)nx = 0;
        int ny = 20-c5;
        if(ny<0)ny = 0;
        ll tmp =get(nx,ny);
        ans+=tmp;
        add(c2,c5);
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3760