akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/arc084/tasks/arc084_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        a: [i32; n],
        b: [i32; n],
        c: [i32; n]
    };

    let (mut a, mut b, mut c) = (a, b, c);
    a.sort();
    b.sort();
    c.sort();

    let mut ai = 0;
    let mut ci = 0;
    let mut ans = 0i64;
    for i in 0..n {
        let center = b[i];
        while ai < n && a[ai] < center {
            ai += 1;
        }
        while ci < n && c[ci] <= center {
            ci += 1;
        }
        ans += (ai as i64) * (n - ci) as i64;
    }
    println!("{}", ans);
}


Measured memory_bytes: 10360
#include"bits/stdc++.h"
using namespace std;

int L;
int main(){
	cin >> L;
	stack<int> st;
	bool isIn[101] ={};
	for(int i=0; i<L; i++){
		int c;
		cin >> c;
		if(c < 0){
			if(st.size() == 0 || st.top() != -c){
				cout << i+1 << endl;
				return 0;
			}
			st.pop();
			isIn[-c] = false;
		}
		else{
			if(isIn[c]){
				cout << i+1 << endl;
				return 0;
			}
			st.push(c);
			isIn[c] = true;
		}
	}
	cout << "OK" << endl;
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383

int main(){
   
    fast;
    string s,t;
    cin>>s>>t;

    int ans = INT_MAX;
    for(unsigned int i=0;i<=s.length() - t.length();i++){
        int temp = 0;
        for(unsigned int j=0;j<t.length();j++){
            if(s[i + j] != t[j]){
                temp++;
            }
        }
       // cout<<temp<<endl;
        ans = min(ans,temp);
    }
    if(ans != INT_MAX)
    cout<<ans<<endl;
    else
    {
        cout<<0<<endl;
    }
    








}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;
  cout << (N + 1) / 2 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7
N = 2 * 10 ** 6 + 10

fac = [0] * N
finv = [0] * N
inv = [0] * N

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, N):
    fac[i] = fac[i - 1] * i % mod
    # mod pにおける1, 2, ..., nの逆元
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def com(n, k):
    global fac, finv, mod
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

def g(r, c):
    return (com(r + c + 2, r + 1) - 1) % mod

r1, c1, r2, c2 = map(int, input().split())

answer = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
answer %= mod
print(answer)


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll a;
	long double b;
	cin>>a>>b;
	cout<<ll((a*(int(b*100+0.001)))/100)<<endl;
	return 0;
}

Measured memory_bytes: 3728
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
        k: usize,
        mut a: [usize; n],
        mut f: [usize; n],
    }

    a.sort();
    f.sort_by(|a, b| b.cmp(a));

    let mut max = 0;
    for i in 0..n {
        max = cmp::max(max, a[i] * f[i]);
    }
    if a.iter().sum::<usize>() <= k {
        println!("{}", 0);
        return; 
    }
    let mut left = 0;
    let mut right = max;
    while right - left > 1 {
        let mid = (left + right) / 2;
        if check(mid, &a, &f, k) {
            right = mid;
        } else {
            left = mid;
        }
    }
    println!("{}", right);
}

fn check(grade: usize, a: &Vec<usize>, f: &Vec<usize>, limit: usize) -> bool {
    let n = a.len();
    let mut count = 0;
    for i in 0..n {
        let t = grade / f[i];
        if t < a[i] {
            count += a[i] - t;
        }
    }
    if count <= limit {
        return true;
    } else {
        return false;
    }
}


Measured memory_bytes: 8616
// D - Handstand 2
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N;

ll solve(){
	ll ans=0;
	map<pair<int,int>,int> C;//[{i,j}]<int>=count

	rp(k,1,N+1){
		string s = to_string(k);
		int i = s[0]-'0';
		int j = s[s.size()-1]-'0';
		C[{i,j}]++;
	}

	rp(k,1,N+1){
		string s = to_string(k);
		int i = s[0]-'0';
		int j = s[s.size()-1]-'0';
		ans += C[{j,i}];
	}

	return ans;
}

int main(){
	cin>>N;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n, lim;
  scanf ("%" SCNi32 "%" SCNi32, &n, &lim);
  i32 *dp = (i32 *) calloc (lim + 1, sizeof (i32));
  while (n--) {
    i32 v, w, m;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &v, &w, &m);
    i32 k = 1;
    while (m > 0) {
      i32 a = v * k;
      i32 b = w * k;
      for (i32 i = lim; i >= b; --i) {
	if (dp[i] < dp[i - b] + a) {
	  dp[i] = dp[i - b] + a;
	}
      }
      m -= k;
      k *= 2;
      if (k > m) {
	k = m;
      }
    }
  }
  printf ("%" PRIi32 "\n", dp[lim]);
}

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



Measured memory_bytes: 2112
gets.to_i.times do
  y,m,d = gets.split.map(&:to_i)
  res = 0
  while y < 1000
    res, d = res + 1, d + 1
    md = (y % 3 == 0 || m % 2 == 1) ? 20 : 19
    d, m = 1, m + 1 if d > md
    m, y = 1, y + 1 if m > 10
  end
  puts res
end

Measured memory_bytes: 6108
unittest
{
	assert( [ "3 2", "#.#", ".#.", "#.#", "#.", ".#" ].parse.expand.solve == "Yes" );
	assert( [ "4 1", "....", "....", "....", "....", "#" ].parse.expand.solve == "No" );
	
	assert( [ "3 2", "..#", ".#.", "#.#", "#.", ".#" ].parse.expand.solve == "Yes" );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto ass = new dchar[][]( nm[ 0 ] );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.to!( dchar[] );
	}
	auto bss = new dchar[][]( nm[ 1 ] );
	foreach( ref bs; bss )
	{
		input.popFront;
		bs = input.front.to!( dchar[] );
	}
	return tuple( ass, bss );
}

auto solve( dchar[][] ass, dchar[][] bss )
{
	for( auto ai = 0L; ai <= ass.length - bss.length; ai++ )
	{
		LOOP: for( auto aj = 0L; aj <= ass[ 0 ].length - bss[ 0 ].length; aj++ )
		{
			for( auto bi = 0L; bi < bss.length; bi++ )
			{
				for( auto bj = 0L; bj < bss[ 0 ].length; bj++ )
				{
					if( ass[ ai + bi ][ aj + bj ] != bss[ bi ][ bj ] ) continue LOOP;
				}
			}
			
			return "Yes";
		}
	}
	
	return "No";
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
#define MAXN 201010

int A[MAXN];
int B[MAXN];
int N,ans;
vi V;
vi O;

int main(){
	cin>>N;
	for (int i=1;i<=N;++i){
		cin>>A[i];
	}
	for (int i=1;i<=N;++i){
		cin>>B[i];
	}
	for (int bit=0;bit<=29;++bit){
		V.clear();
		O.clear();
		int tmp=0;
		for (int i=1;i<=N;++i){
			V.pb(A[i]%(1<<bit));
			tmp += ((A[i]&(1<<bit)) > 0)*N;
			tmp %= 2;
		}
		sort(ALL(V));
		for (int i=1;i<=N;++i){
			O.pb(B[i]%(1<<bit));
			tmp += ((B[i]&(1<<bit)) > 0)*N;
			tmp%=2;
		}
		// cout<<tmp<<'\n';
		sort(ALL(O));
		reverse(ALL(V));
		// for (auto i : O)cout<<i<<' ';cout<<'\n';
		// for (auto i : V)cout<<i<<' ';cout<<'\n';
		int ind = -1;
		for (auto i : O){
			while (ind+1<N && V[ind+1]+i >= (1<<bit))++ind;
			tmp += (ind + 1);
			tmp %= 2;
		}
		ans += (tmp%2)*(1<<bit);
		// return 0;
	}
	cout<<ans;
}

Measured memory_bytes: 6384
import java.util.Scanner;

/**
 * Created by wenzhong on 2016/8/21.
 */
public class Main {
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        while(in.hasNext()){
            String s=in.next();
            int a=0;
            int b=0;
            int c1=0;
            int d=0;
            for(char c:s.toCharArray()){
                switch (c){
                    case 'N':a++;
                        break;
                    case 'S':b++;
                        break;
                    case 'E':c1++;
                        break;
                    case 'W':d++;
                        break;
                }
            }
            boolean flag=true;
            flag&=((a==0&&b==0)||(a!=0&&b!=0))&((c1==0&&d==0)||(c1!=0&&d!=0));
            System.out.println(flag?"Yes":"No");
        }
    }
}


Measured memory_bytes: 8788
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
				
		System.out.println(Math.abs(x-a)<Math.abs(x-b) ? "A" : "B");
	}
}


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

int a[100000];
vector<int>E[100000];
int s;
int dfs(int u, int p) {
	int cnt = 0, Max = 0;
	for (int v : E[u]) {
		if (v != p) {
			int a = dfs(v, u);
			cnt += a; Max = max(Max, a);
		}
	}
	if (s == u)return a[u] - cnt;
	if (E[u].size() == 1)return a[u];
	if (a[u] * 2 < cnt || Max > a[u] || a[u] * 2 - cnt > a[u]) {
		puts("NO"); exit(0);
	}
	return a[u] * 2 - cnt;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &a[i]);
	rep(i, n - 1) {
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		E[a].push_back(b); E[b].push_back(a);
	}
	rep(i, n) {
		if (E[i].size() == 1)s = i;
	}
	puts(dfs(s, -1) ? "NO" : "YES");
}

Measured memory_bytes: 13952
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

int main()
{
    long long N;
    int i, operations, e, last;

    scanf("%lld", &N);

    operations = 0;
    for(i = 2; i <= 1000000; ++i){
        if(N % i == 0){
            e = 0;
            while(N % i == 0){
                ++e;
                N /= i;
            }
            last = 0;
            while(e > last){
                ++operations;
                ++last;
                e -= last;
            }
        }
    }
    if(N != 1)
        ++operations;

    printf("%d", operations);

    return 0;
}


Measured memory_bytes: 1736
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	string s1, s2;
	cin >> s1 >> s2;
	i64 ans = 0;
	char pre = 'x';
	int i = 0;
	while (i < n)
	{
		if (i == 0)
		{
			if (s1[i] == s2[i])
			{
				ans = 3;
				pre = 'x';
				i++;
			}
			else
			{
				ans = 6;
				pre = 'y';
				i += 2;
			}
		}

		else if (s1[i] == s2[i])
		{
			if (pre == 'x')
				ans *= 2;
			pre = 'x';
			i++;
		}
		else
		{
			if (pre == 'x')
				ans *= 2;
			else
				ans *= 3;
			pre = 'y';
			i += 2;
		}
	}

	print(ans % 1000000007);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> c(N, 0);
  c[0] = 3;

  int ans = 1;
  REP(i, N){
    (ans *= c[A[i]]) %= MOD;
    c[A[i]]--; c[A[i]+1]++;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[100+5];
 
 int main()
 {
   int n;
   cin>>n;
   for(int i=0;i<n;i++) cin>>arr[i];
   for(int i=0;i<n/2;i++) swap(arr[i],arr[n-i-1]);
   for(int i=0;i<n-1;i++) cout<<arr[i]<<" ";
   cout<<arr[n-1]<<endl;
   //while(1);
   return 0;
 }
 
 

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define iter vector<int>::iterator
#define mod 1000000007
#define inf 1e16

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;

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

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

    int dp[n][n];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<n;j++)
    	{
    		dp[i][j]=inf;
    	}
    }
    for(int i=0;i<n;i++)
    	dp[i][i]=0;

    int temp;

    for(int l=1;l<n;l++)
    {
    	for(int i=0,j=l;j<n;i++,j++)
    	{
    		for(int k=i;k<j;k++)
    		{
    			temp=dp[i][k]+dp[k+1][j]+sum[i][j];

    			if(dp[i][j]>temp)
    			{
    				dp[i][j]=temp;
    			}
    		}
    	}
    }
    cout<<dp[0][n-1]<<"\n";
}

Measured memory_bytes: 2816
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



string str;

int main() {
    while ( getline(cin, str) ) {
        string sub;
        istringstream sin(str);

        stack<double> st;
        for (int i = 0; i < 1000; ++i) st.push(0);
        
        while (sin >> sub) {
            if (sub == "+") {
                double b = st.top(); st.pop();
                double a = st.top(); st.pop();
                double t = a+b;
                st.push(t);
            }
            else if (sub == "-") {
                double b = st.top(); st.pop();
                double a = st.top(); st.pop();
                double t = a-b;
                st.push(t);
            }
            else if (sub == "*") {
                double b = st.top(); st.pop();
                double a = st.top(); st.pop();
                double t = a*b;
                st.push(t);
            }
            else if (sub == "/") {
                double b = st.top(); st.pop();
                double a = st.top(); st.pop();
                double t = a/b;
                st.push(t);
            }
            else {
                istringstream sin2(sub);
                double num; sin2 >> num;
                st.push(num);
            }
        }
        
        cout << fixed << setprecision(9) << st.top() << endl;
    }
    return 0;
}


Measured memory_bytes: 1332
#include<bits/stdc++.h>
#define rep(i, a, b) for (register int i=(a); i<=(b); ++i)
#define per(i, a, b) for (register int i=(a); i>=(b); --i)
using namespace std;
const int N=100005;
vector<int> G[N];
int sum[N], fa[N], ex=1, ey=1, ans;

inline int read()
{
 	int x=0,f=1;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*f;
}

int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}

void dfs(int u, int f, int val)
{
	sum[u]=val; fa[u]=f;
	for (int v: G[u]) if (v^f)
		dfs(v, u, -val), sum[u]+=sum[v];
}

int main()
{
	int n=read(), m=read();
	rep(i, 1, n) fa[i]=i;
	rep(i, 1, m)
	{
		int x=read(), y=read(), fx=find(x), fy=find(y);
		if (fx^fy) fa[fx]=fy; else {ex=x, ey=y; continue;}
		G[x].push_back(y); G[y].push_back(x);
	}
	dfs(ex, 0, 1);
	if (n==m+1) if (sum[ex]) return puts("-1"), 0;
	if (n==m)
	{
		vector<int> cir;
		for (int i=ey; i; i=fa[i]) cir.push_back(sum[i]);
		if (!(cir.size()&1))
		{
			if (sum[ex]) return puts("-1"), 0;
			sort(cir.begin(), cir.end());
			for (int i=ey; i; i=fa[i]) sum[i]-=cir[cir.size()>>1];
		}
		else
		{
			if (sum[ex]&1) return puts("-1"), 0;
			for (int i=ey; i; i=fa[i]) sum[i]-=sum[ex]>>1;
		}
	}
	rep(i, 1, n) ans+=abs(sum[i]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 14972
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	float v;
	while (scanf("%f", &v) != EOF) {
		printf ("%d\n", (int)ceil((v * v / 19.6 + 5) / 5.0 + 0.000000001));
	}
	return 0;
}

Measured memory_bytes: 0
(defun solve(a b c)
  (let* ((l (sort (list a b c) #'<=)))
    (if (some #'evenp l)
        0
        (* (first l) (second l)))))

(defun main()
  (let ((a (read))
        (b (read))
        (c (read)))
    (princ (solve a b c))))

(main)


Measured memory_bytes: 24356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=6105,INF=1<<30;
map<string,int> MA;
struct edge{
    int topos;
    int cost;
};
vector<edge> G[MAX];
bool ok[MAX];

int dis[MAX][2005];

void dijkstra(int spos,int scap,int maxi){
    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> PQ;
    
    PQ.push(mp(0,mp(spos,scap)));
    
    while(!PQ.empty()){
        auto u=PQ.top();PQ.pop();
        
        if(dis[u.se.fi][u.se.se]<u.fi) continue;
        
        if(ok[u.se.fi]){
            if(chmin(dis[u.se.fi][maxi],dis[u.se.fi][u.se.se])){
                PQ.push(mp(dis[u.se.fi][maxi],mp(u.se.fi,maxi)));
            }
        }
        
        for(auto to:G[u.se.fi]){
            int a=to.topos,c=to.cost;
            if(u.se.se-c>=0&&chmin(dis[a][u.se.se-c],dis[u.se.fi][u.se.se]+c)){
                PQ.push(mp(dis[a][u.se.se-c],mp(a,u.se.se-c)));
            }
        }
        
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M,cap;cin>>N>>M>>cap;
        cap*=10;
        if(N+M+cap==0) break;
        
        string s,g;cin>>s>>g;
        
        for(int i=0;i<2*N+100;i++){
            G[i].clear();
            ok[i]=0;
            for(int j=0;j<=cap;j++){
                dis[i][j]=INF;
            }
        }
        MA.clear();
        
        MA[s]=1;
        MA[g]=1;
        vector<pair<string,string>> E(N);
        vector<int> D(N);
        for(int i=0;i<N;i++){
            cin>>E[i].fi>>E[i].se;
            MA[E[i].fi]=1;
            MA[E[i].se]=1;
            cin>>D[i];
        }
        vector<string> P(M);
        for(int i=0;i<M;i++){
            cin>>P[i];
            MA[P[i]]=1;
        }
        int id=0;
        for(auto a:MA){
            MA[a.fi]=id;
            id++;
        }
        for(int i=0;i<N;i++){
            int a=MA[E[i].fi],b=MA[E[i].se],c=D[i];
            G[a].push_back(edge{b,c});
            G[b].push_back(edge{a,c});
        }
        for(int i=0;i<M;i++){
            int a=MA[P[i]];
            ok[a]=1;
        }
        dis[MA[s]][cap]=0;
        dijkstra(MA[s],cap,cap);
        
        int ans=INF;
        for(int j=0;j<=cap;j++) chmin(ans,dis[MA[g]][j]);
        
        if(ans==INF) ans=-1;
        
        cout<<ans<<endl;
    }
}




Measured memory_bytes: 76492
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,T,hantei=1;
    cin >> n >> T;
    int c[n],t[n];
    int c_save=1000;
    for(int i=0;i<n;i++){
        cin >> c[i] >> t[i];
    }
    for(int i=0;i<n;i++){
        if(T>=t[i] && c_save>=c[i]){
                c_save = c[i];
                hantei = 0;
        }
    }
    if(hantei == 1) cout << "TLE" << endl;
    else cout << c_save << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<pair<int,int>> ball(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    
    ball[i] = {x, y};
  }
  
  int maxcount = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      
      int p = ball[i].first - ball[j].first;
      int q = ball[i].second - ball[j].second;
      
      int count = 0;
     
      for (int k = 0; k < N; k++) {
        for (int l = 0; l < N; l++) {
          if (k == l) continue;
          
          if (ball[k].first - ball[l].first == p 
             && ball[k].second - ball[l].second == q) count++;
        }
      }
      
      maxcount = max(maxcount, count);
       
    }
  }
  
  cout << N - maxcount << endl;
}

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

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  string s, t; cin >> s >> t;
  int s_len = s.length();
  int t_len = t.length(); 

  vvi dp(s_len + 5, vi(t_len + 5, 0));
  
  rep(i, s_len){
    rep(j, t_len){
      chmax(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));    
      if(s[i] == t[j])
        chmax(dp[i + 1][j + 1], dp[i][j] + 1);
    }
  }

  string ans = "";
  while(s_len > 0 and t_len > 0){
    if(dp[s_len][t_len] == dp[s_len - 1][t_len])
      -- s_len;
    else if(dp[s_len][t_len] == dp[s_len][t_len - 1])
      -- t_len;
    else {
      ans += s[s_len - 1];
      -- s_len;
      -- t_len;
    }
  }

  reverse(all(ans));
  pr(ans);

  return 0;
}


Measured memory_bytes: 35712
#include <stdio.h>
#define INF 5300000
int main(){
  int t,i,num,p[500],m[500][500];
  int minm=INF,l=0,j=0,k=0,q=0;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }
  for(i=1;i<=num;i++){
    m[i][i]=0;
      
  }
  for(l=2;l<num+1;l++){
  
    for(i=1;i<num-l+2;i++){
      j=i+l-1;
      m[i][j]=INF;
  
     for(k=i;k<j;k++){
    q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
       
    if(q<=m[i][j]){
      m[i][j]=q;
  
    }
      }
    }}
  printf("%d\n",m[1][num]);
  return 0;
}


Measured memory_bytes: 2052
n,k = input().split()
d = input().split()

ni = int(n)

f = []
while True:
	for j in range(len(d)):
		if d[j] not in n:
			f.append(True)
		else:
			f.append(False)
	if False not in f:
		break
	f = []
	ni += 1
	n = str(ni)

print(ni)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  ll ans = 0;
  VI l(2*n); rep(i,2*n) cin>>l[i];
  sort(ALL(l));
  rep(i,n) ans += l[2*i];
  cout << ans << endl;


  return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

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

int main()
{
    int h, w, hh, ww;
    ci >> h >> w >> hh >> ww;

    co << (h - hh) * (w - ww) << en;
  
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

void out(bool f){
  std::cout << (f?"YES":"NO") << '\n';
  exit(0);
}
vvl G = vv(100001, 0, 0, ll);
ll root;
vll a(100001), th(100001, -1);

ll dfs(ll now, ll from){
  if(G[now].size()==1) return th[now] = a[now];
  ll s = 0, m = 0;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    ll tmp = dfs(G[now][i], now);
    s += tmp, m = max(m, tmp);
  }
  ll T, L, K;
  if(now==root) {
    K = min(s-m, s/2);
    //std::cout << a[root] << " " << s << " " << m << '\n';
    out(s%2==0&&K==a[now]&&s/2>=m);
    return -1;
  }else{
    T = 2*a[now]-s, L = (s - T)/2, K = min(s-m, s/2);
    if(T<0||L>K||L<0) out(0);
  }
  return th[now] = T;
}

int main(int argc, char const *argv[]) {
  ll x, y, n;std::cin >> n;
  rep(i, 1, n+1) std::cin >> a[i];
  re(i, n-1){
    std::cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  if(n==2) out(a[1]==a[2]);
  for(int i=1;i<=n;i++) if(G[i].size()!=1) root = i;
  dfs(root, -1);
  out(1);
  return 0;
}


Measured memory_bytes: 13056
s = input()
k = int(input())

ssort = sorted(set(s))
cnt, ans = 0, set()
while len(ans) < k:
    for i, si in enumerate(s):
        if si == ssort[cnt]:
            ans |= {s[i:i + j + 1] for j in range(k)}
    cnt += 1
print(sorted(ans)[k - 1])


Measured memory_bytes: 73668
use std::collections::VecDeque;

fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let h: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let w: usize = iter.next().unwrap().parse::<usize>().unwrap();
    
    let mut a = vec![vec![false;w];h];
    let mut que = VecDeque::new();
    for y in 0..h {
        let s: String = iter.next().unwrap().parse::<String>().unwrap();
        let mut chars = s.chars();
        for x in 0..w {
            match chars.next() {
                Some('#') => {
                    a[y][x] = true;
                    que.push_back((y,x,1));
                },
                _ => (),
            }
        }
    }

    let mut cnt = 0;
    while let Some(p) = que.pop_back() {
        for v in adjacent4(p.0, p.1, h, w) {
            if !a[v.0][v.1] {
                cnt = std::cmp::max(p.2, cnt);
                a[v.0][v.1] = true;
                que.push_front((v.0,v.1,p.2 + 1));
            }
        }
    }

    println!("{}", cnt);

}

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(dead_code)]
fn adjacent4(y: usize, x: usize, h: usize, w: usize) -> Box<Iterator<Item = (usize, usize)>> {
    static DYDX: [(isize, isize); 4] = [(-1, 0), (1, 0), (0, -1), (0, 1)];
    Box::new(DYDX.iter().filter_map(move |&(dy, dx)| {
        let ny = y as isize + dy;
        let nx = x as isize + dx;
        if nx >= 0 && nx < w as isize && ny >= 0 && ny < h as isize {
            Some((ny as usize, nx as usize))
        } else {
            None
        }
    }))
}


Measured memory_bytes: 30708
#include <stdio.h>
#include <stdlib.h>
int binarySearch(int sorted_list[], int number, int element);
int main(int argc, char** argv) {
    int number1,number2;
    int readScan = scanf("%d", &number1);
    int array1[number1];
    for(int i=0;i<number1;i++)
    {
        int readScan = scanf("%d", &array1[i]);
    }
    int readScan1 = scanf("%d", &number2);
    int array2[number2];
    for(int i=0;i<number2;i++)
    {
        int readScan = scanf("%d", &array2[i]);
    }
    int key;
    int count=0; 
    int left,right,mid;
    left=0;
    right = number1-1;
    for(int i=0;i<number2;i++)
    {
        if(binarySearch(array1, number1,array2[i]) != NULL)
            count++;
    }
    printf("%d\n", count);
    return(0);
}
int binarySearch(int sorted_list[], int number, int element)
{
    int low, high;
    low = 0;
    high = number-1;
    int middle;
    while (low <= high)
    {
        middle = low + (high - low)/2;
        if (element > sorted_list[middle])
            low = middle + 1;
        else if (element < sorted_list[middle])
            high = middle - 1;
        else
            return middle;
    }
    return NULL;
}




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

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

struct Point { double x, y; };
typedef Point Vector;
#define EPS (1e-10)
double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}
int main()
{
	int q;
	Point p[3];
	Vector v1, v2;
	double dotv;
	double v1len;
	Point ans;

	cin >> p[1].x >> p[1].y >> p[2].x >> p[2].y;
	cin >> q;

	v1.x = p[2].x - p[1].x;
	v1.y = p[2].y - p[1].y;
	v1len = sqrt(v1.x * v1.x + v1.y * v1.y);

	rep(i, q) {
		cin >> p[0].x >> p[0].y;

		v2.x = p[0].x - p[1].x;
		v2.y = p[0].y - p[1].y;

		dotv = dot(v1, v2);

		ans.x = p[1].x + v1.x * dotv / v1len / v1len;
		ans.y = p[1].y + v1.y * dotv / v1len / v1len;

		printf("%.10lf %.10lf\n", ans.x, ans.y);
	}

	return 0;
}


Measured memory_bytes: 3280
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

typedef string::const_iterator ParseState;

class ParseError {
};

int expression(ParseState &begin);

int term(ParseState &begin);

int factor(ParseState &begin);

int num(ParseState &begin);

int NOT(int a) {
    return 2 - a;
}

int AND(int x, int y) {
    if (x == 0 || y == 0) return 0;
    if (x == 2 && y == 2) return 2;
    return 1;
}

int OR(int x, int y) {
    if (x == 2 || y == 2) return 2;
    if (x == 0 && y == 0) return 0;
    return 1;
}

int expression(ParseState &begin) {
    int res = 0;
    if (*begin == '(') {
        begin++;
        int d1 = expression(begin);
        int d2;
        if (*begin == '+') {
            begin++;
            d2 = expression(begin);
            res = OR(d1, d2);
        } else if (*begin == '*') {
            begin++;
            d2 = expression(begin);
            res = AND(d1, d2);
        }
        begin++;
    } else {
        res += term(begin);
    }
    return res;
}

int term(ParseState &begin) {
    int res;
    if (*begin == '-') {
        begin++;
        res = NOT(expression(begin));
    } else if (isdigit(*begin)) {
        res = *begin - '0';
        begin++;
    }
    return res;
}

int main() {

    while (true) {

        string s;
        cin >> s;

        if (s.size() == 1 && s[0] == '.') break;

        int ans = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    string t = s;
                    for (int l = 0; l < t.size(); l++) {
                        if (t[l] == 'P') t[l] = (char) ('0' + i);
                        if (t[l] == 'Q') t[l] = (char) ('0' + j);
                        if (t[l] == 'R') t[l] = (char) ('0' + k);
                    }
                    auto begin = t.cbegin();
                    //cout << expression(begin);
                    if (expression(begin) == 2) {
                        ans++;
                      //  cout << t << endl;
                    }
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}





























Measured memory_bytes: 3144
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x;
    cin >> x;
    if (x == 1) {
        cout << "Hello World\n";
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,K;
 int display = 1;
  cin >> N >> K;
 for(int i = 0; i < N ; i++ ){
   if(display * 2 - display < K){
    display *= 2; 
   } else {
     display += K;
 }

 }
   cout << display << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

int main(){
  int n;
  int a[300000];
  vector<int> b;
  cin>>n;
  for(int i = 0;i<n;i++){
    cin>>a[i];
  }

  for(int i = n-1;i>=0;i-=2)
    b.push_back(a[i]);

  for(int i = (n%2==0)?0:1;i<n;i+=2)
    b.push_back(a[i]);

  for(int i = 0;i<n;i++){
    cout<<b[i];
    if(i != n-1){
      cout<<" ";
    }else{
      cout<<endl;
    }
  }
    

  return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
const int N=100;

int bin(int n,int searchEle,vector<int> a){
    int l =0;
    int r = n-1;
    int eleindex = -1;
    while(l<=r){
         //   cout<<l<<r<<"lr"<<endl;
      int mid = l+((r-l)/2);
      // cout<<a[mid]<<searchEle<<endl;
      if(a[mid]<=searchEle){
        eleindex = mid;
        l = mid+1;
      }else{
        r= mid-1;
      }
    }
    return eleindex;
}
int main(){
  int n,x;
  cin>>n>>x;
  int y;
  vector<int> prel(n+1,0);
  prel[0] = 0;
  for(int i=1;i<=n;i++){
    cin>>y;
    prel[i]=prel[i-1]+y;
  }
//   for(int i=0;i<prel.size();i++){
//    cout<<prel[i]<<endl;
//  }
  cout<<bin(prel.size(),x,prel)+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

double snuke(ll i){
    int digit = 0;
    ll num = i;
    while(0 < num){
        digit += num % 10;
        num /= 10;
    }
    return 1. * i / digit;
}

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

    vector<ll> v;
    for(int i=1; i<=9; i++) v.emplace_back(i);

    ll base = 9;
    for(int i=0; i<14; i++){
        for(int j=1; j<=999; j++){
            string s = to_string(j) + to_string(base);
            v.emplace_back(stoll(s));
        }

        base *= 10;
        base += 9;
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    for(int i=0; i<v.size(); i++){
        for(int j=i+1; j<v.size(); j++){
            if(snuke(v[i]) > snuke(v[j])){
                v.erase(v.begin() + i--);
                break;
            }
        }
    }
  
    for(int i=0; i<k; i++) cout << v[i] << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
/*#include <stdlib.h>*/
int main(int argc, char *argv[])
{		
   int max,min,mod;
   scanf("%d%d",&max,&min);
   if(max==0||min==0)
   {
		printf("0\n");
		return 0;
   }
   
   if(max<min)
   {
   	mod=max;
   	max=min;
   	min=mod;
   }
   mod=max%min;
   while(mod!=0)
   {
   	max=min;
   	min=mod;
   	mod=max%min;
   }
   printf("%d\n",min);
	return 0;
}

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

using namespace std;
inline void FAST_IO(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

int main() {
	FAST_IO();
	int a,b,t;
	cin >> a >> b >> t;
	
	cout << (t/a)*b << endl;
	
    return 0;
}

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

lim=60
to=[[0]*n for i in range(lim)]

for i in range(n):
  aft=a[i]
  aft-=1
  to[0][i]=aft

for i in range(lim-1):
  for j in range(n):
    to[i+1][j]=to[i][to[i][j]]

v=0
for i in range(lim,-1,-1):
#  l=2**i
  l=1<<i
  if l<=k:
    v=to[i][v]
    k-=l

print(v+1)

Measured memory_bytes: 174992
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String str[] =S.split(""); 
        int sum = 0;
        for(int i=0;i<3;i++)
        {
            if(str[i].equals(str[i+1]))
            {
                sum++;
            }
        }
        if(sum == 0)
        {
            System.out.println("Good");
        }
        else System.out.println("Bad");
    }
}


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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    bill_count, total_yen = list(map(int, input().split()))
    bill_max = 2000

    five_thousand_yen_count = 0
    one_thousand_yen_count = 0

    for z in range(bill_max + 1):
        for y in range(bill_max + 1):
            if (5 * y + 9 * z) == (10 * bill_count - total_yen / (10 ** 3)):
                five_thousand_yen_count = y
                one_thousand_yen_count = z
                break

    ten_thousand_yen_count = bill_count - (five_thousand_yen_count + one_thousand_yen_count)

    condition = ((10 * ten_thousand_yen_count) + (5 * five_thousand_yen_count) + one_thousand_yen_count) == (total_yen / 1000)
    condition1 = ten_thousand_yen_count >= 0
    condition2 = five_thousand_yen_count >= 0
    condition3 = one_thousand_yen_count >= 0

    if condition and condition1 and condition2 and condition3:
        print(str(ten_thousand_yen_count) + ' ' + str(five_thousand_yen_count) + ' ' + str(one_thousand_yen_count))
    else:
        print('-1 -1 -1')


Measured memory_bytes: 3188
import collections
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
f = collections.Counter(d)
# print(f)
if d[0] != 0 or f[0] != 1:  # 0は一個だけ
    print(0)
    exit()
ans = 1
box = 1  # 値自体の個数を保存
maxd = max(d)

for i in range(maxd+1):
    ans = ans*box**f[i]
    ans %= mod
    box = f[i]
print(ans)


Measured memory_bytes: 98592