akhauriyash/Code-Regression huggingface dataset:
/// C: Traveling Plan <https://beta.atcoder.jp/contests/arc093/tasks/arc093_a>
/// TLE: 2 sec
/// MLE: 256 MB

fn main() {
    let n: usize = reads()[0];
    let a: Vec<i32> = reads();

    let mut ds = vec![0; n];
    for i in 0..n {
        let (dist, prev) = if i == 0 {
            (0, 0)
        } else {
            (ds[i - 1], a[i - 1])
        };
        ds[i] = dist + (prev - a[i]).abs();
    }
    // eprintln!("{:?}", ds);

    let mut es = vec![0; n];
    for i in (0..n).rev() {
        let (dist, prev) = if i == n - 1 {
            (0, 0)
        } else {
            (es[i + 1], a[i + 1])
        };
        es[i] = dist + (prev - a[i]).abs();
    }
    // eprintln!("{:?}", es);

    for i in 0..n {
        let (l, p1) = if i == 0 {
            (0, 0)
        } else {
            (ds[i - 1], a[i - 1])
        };
        let (r, p2) = if i == n - 1 {
            (0, 0)
        } else {
            (es[i + 1], a[i + 1])
        };
        println!("{}", l + r + (p1 - p2).abs());
    }
}

//----- Libraries -----

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

//----- Tests -----

#[cfg(test)]
mod test {
    use std::io::Write;
    use std::process::{Command, Stdio};

    fn do_test(sample_input: &str, sample_output: &str) {
        let mut child = Command::new("cargo")
            .args(&["run", "--bin", "arc093_a", "-q"])
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();

        write!(child.stdin.as_mut().unwrap(), "{}", sample_input.trim()).unwrap();
        let output = child.wait_with_output().unwrap();

        assert_eq!(
            sample_output.trim(),
            String::from_utf8(output.stdout).unwrap().trim()
        );
    }

    #[test]
    fn sample1() {
        let input = r#"
            3
3 5 -1
        "#;
        let output = r#"
            12
8
10
        "#;
        do_test(input, output);
    }
    #[test]
    fn sample2() {
        let input = r#"
            5
1 1 1 2 0
        "#;
        let output = r#"
            4
4
4
2
4
        "#;
        do_test(input, output);
    }
    #[test]
    fn sample3() {
        let input = r#"
            6
-679 -2409 -3258 3095 -3291 -4462
        "#;
        let output = r#"
            21630
21630
19932
8924
21630
19288
        "#;
        do_test(input, output);
    }
}


Measured memory_bytes: 7036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

//ll fpow(ll b,ll p,ll mod){
//    b %=mod;
//    ll ans=1;
//    while(p){
//
//        if (p&1){
//            ans *=b;
//            ans %=mod;
//        }
//        b *=b;
//        b%=mod;
//        p >>=1;
//    }
//    return ans;
//}


int main()
{
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &c:a) cin >> c;
    if (n==1) cout << "Yes" << endl;
    else {
        for(int i=0;i<n-1;++i){
            if (a[i] - a[i+1] > 1){
                cout <<"No" << endl;
                return 0;
            }else if (a[i] - a[i+1] == 1){
                a[i+1] +=1;
            }
        }
        cout <<"Yes";
//


    }
    return 0;
}


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

def dfs(s):
    if int(s) >n:
        return 0
    
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s+c)
    
    return ret

print(dfs('0'))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cat M;
	cin >> N >> M;
	int K = N/2+1-(N%2 == 0);
	vector<cat> dp(N, 0);
	dp[0] = 1;
	for(int i = 1; i <= K; i++) {
		if(N%2 != 0 && i == K) {
			for(int j = N-1-K; j >= 0; j--) {
				dp[j+K] += dp[j];
				if(dp[j+K] >= M) dp[j+K] -= M;
			}
			continue;
		}
		for(int r = 0; r < i; r++) {
			cat s0 = 0, s1 = 0;
			for(int j = r, k = 0; j < N; j += i, k++) {
				s0 += dp[j];
				s1 += dp[j] * k;
				dp[j] = (s0 * (k+1) - s1) % M;
			}
		}
	}
	cat ans = 0;
	for(int i = 0; i < N; i++) ans += dp[i];
	ans %= M;
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt(),m=sc.nextInt();
        int amin=100001;
        int[] as=new int[a];
        for(int i=0;i<a;i++){
            as[i]=sc.nextInt();
            amin=(int)Math.min(as[i],amin);
        }
        int[] bs=new int[b];
        int bmin=100001;
        for(int i=0;i<b;i++){
            bs[i]=sc.nextInt();
            bmin=(int)Math.min(bmin,bs[i]);
        }
        int mmin=200001;
        int x=0,y=0,c=0;
        for(int i=0;i<m;i++){
            x=sc.nextInt();
            y=sc.nextInt();
            c=sc.nextInt();
            mmin=(int)Math.min(as[x-1]+bs[y-1]-c,mmin);
        }
        System.out.println((int)Math.min(amin+bmin,mmin));
    }
}

Measured memory_bytes: 134052
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){
    int n;
    cin>>n;
    int x = n/100;
    int answer = x*100 + x*10 + x;
    if(answer>=n) cout<<answer<<endl;
    else{
        x++;
        answer = x*100 + x*10 + x;
        cout<<answer<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
int func1(int X){
  return X>=0?X:-X;
  }
int main(){
  string S;
  cin>>S;
  int ans=1000;
  rep(i,2,S.size()){
    string N;
    N+=S.at(i-2);
    N+=S.at(i-1);
    N+=S.at(i);
    int X=stoi(N);
    ans=min(ans,func1(X-753));
    }
  cout<<ans<<endl;
  }

Measured memory_bytes: 256
def f(n):
    if n % 2 == 0:
        return n/2
    else:
        return 3*n+1

s = int(input())
a = [s]
while 1:
    m = f(s)
    if a.count(m) > 0:
        print(len(a) + 1)
        exit()
    a.append(m)
    s = m






Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qpow(ll a, ll b)
{
    ll r = 1;
    for (;b;b>>=1,a=a*a)
        if (b&1)
            r=r*a;
    return r;
}
ll c(ll n, ll k)
{
    if (k < 0 || k > n)
        return 0;
    ll ret = 1;
    for (int i = 0; i < k; ++i)
        ret = ret * (n - i) / (i + 1);
    return ret;
}
ll solve(string s, int k)
{
    int n = s.size();
    if (n == 0 || k == 0)
        return 0;
    long long ans = 0;
    ans += (s[0] - '1') * c(n - 1, k - 1) * qpow(9, k - 1);
    ans += c(n - 1, k) * qpow(9, k);
    int j;
    for (j = 1; j < n; ++j)
        if (s[j] != '0')
            break;
    return ans + solve(s.substr(j), k - 1);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    int w = 0;
    for (char c : s)
        w += c != '0';
    cout << solve(s, k) + (w >= k) << endl;
}


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

int main(void){
    int n, money=100000;
    cin >> n;
    while(n--){
        money*=1.05;
        money+=(money%1000==0? 0:1000-money%1000) ;
    }
    cout << money << "\n";
}



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

int main(){
  string S;
  cin >> S;
  vector<int> C(26);
  string ans="yes";
  for(int i=0; i<S.size(); i++){
    if(C.at(S.at(i)-97)>0){
      ans="no";
      break;
    }
    else{
      C.at(S.at(i)-97)++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int i,j,k,l;
char trr[50];
scanf("%s",trr);

for(i=0;i<5;i++)
printf("%c",trr[i]);
if(trr[5]==',')
printf(" ");
else printf("%c",trr[5]);
for(i=6;i<=12;i++)
printf("%c",trr[i]);
if(trr[13]==',')
printf(" ");
else printf("%c",trr[13]);
for(i=14;i<19;i++)
printf("%c",trr[i]);
printf("\n");






return 0;}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char c;
    cin >> c;
    if (c=='a' || c=='i' || c=='u' || c=='e' || c=='o')
    {
        cout << "vowel" << endl;
    }
    else
    {
        cout << "consonant" << endl;
    }
    
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        h: [usize; n],
        ab: [(usize, usize); m],
    }
    // annotate for rust-analyzer
    let n: usize = n;
    let m: usize = m;
    let h: Vec<usize> = h;
    let ab: Vec<(usize, usize)> = ab;

    let mut map = HashMap::<usize, Vec<usize>>::new();

    for i in 0..m {
        (*map.entry(ab[i].0).or_insert(Vec::new())).push(ab[i].1);
        (*map.entry(ab[i].1).or_insert(Vec::new())).push(ab[i].0);
    }

    let mut ans = 0;
    ans += n - map.iter().count();
    for (k, v) in map {
        if v.iter().all(|&x| h[k - 1] > h[x - 1]) {
            ans += 1;
        }
    }

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


Measured memory_bytes: 15060
N = int(input())
if 1 <= N and N < 10:
    ans = N
if 10 <= N  and N < 100:
    ans = 9
if 100 <= N and N < 1000:
    ans = 9 + N - 99
if 1000 <= N and N < 10000:
    ans = 9 + 999 - 100 + 1
if 10000 <= N and N < 100000:
    ans = 9 + (999 - 100 + 1) + N - 9999
if N == 100000:
    ans = 9 + (999 - 100 + 1) + N - 9999 - 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
ll INF=1e12;
/*二分探索の参考になる問題*/
int main(void){
    int n;
    ll k;
    cin>>n>>k;
    vector<int>a(n);
    vector<int>f(n);
    rep(i, n) cin>>a[i];
    rep(i, n) cin>>f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());//降順ソート
    ll left=-1;
    ll right=INF;
    while((right-left)>1){
        ll mid=(left+right)/2;
        ll sum=0;
        rep(i, n){
            sum+=max(a[i]-mid/f[i], (ll)0);
        }
        if(sum<=k) right=mid;
        else left=mid;
    }
    cout<<right<<endl;
    return 0;
}

Measured memory_bytes: 1792
while true
    w, h = gets.chomp.split.map(&:to_i)
    break if [w, h] == [0, 0]
    x, y, d = 1, 1, 0
    while true
        command, l = gets.chomp.split
        adds = [[0, 1], [1, 0], [0, -1], [-1, 0]]
        case command
        when "FORWARD"
            x, y = x + adds[d][0] * l.to_i, y + adds[d][1] * l.to_i
        when "BACKWARD"
            x, y = x - adds[d][0] * l.to_i, y - adds[d][1] * l.to_i
        when "RIGHT"
            d = (d + 1) % 4
        when "LEFT"
            d = (d - 1) % 4
        when "STOP"
            break
        end
        x = 1 if x < 1
        x = w if x > w
        y = 1 if y < 1
        y = h if y > h
    end
    puts "#{x} #{y}"
end


Measured memory_bytes: 6840
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
double Pi = 3.141592653589793238;
using namespace std;
using Graph = vector<vector<ll>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//

int main() {
	int N; cin >> N;
	ll a[100010],ans = 1;
	bool flag = 1;

	rep(i, N) {
		cin >> a[i];
		if (a[i] == 0) {
			flag = 0;
			break;
		}
	}
	if (flag) {
		rep(i, N) {
			if ((ll)1000000000000000000 / ans >= a[i])ans *= a[i];
			else {
				flag = 0;
				break;
			}
		}
		if (flag) cout << ans << endl;
		else cout << -1 << endl;
	}
	else cout << 0 << endl;
	

	return 0;
}


Measured memory_bytes: 4420
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
struct Edge {
	int s;
	int t;
	Edge(int s, int t) :s(s), t(t) {}
};

ll N, M;
ll ans = 0;

void dfs(ll n,ll x, vector<vector<Edge>> &G, vector<bool> used) {
	if (x == N - 1) { ans++; return; }
	used[n] = true;
	for (auto e : G[n]) {
		int next = e.t;
		if (!used[next]) {
			dfs(next, x + 1, G, used);
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	cin >> N >> M;
	vector<vector<Edge>> G(N);
	for (int i = 0; i < M;i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(Edge(a, b));
		G[b].push_back(Edge(b, a));
	}
	vector<bool> used(N, false);
	dfs(0,0,G, used);
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
      @author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

double head_prob[3000];
double dp[3000][3000];
int n; 
// Base Case construction is really crucial
double Top_Down(int i, int heads) {
    // Base Case
    if(i == 0 && heads == 0) return 1;
    if(i == 0 && heads != 0) return 0;

    if(dp[i][heads] != 0) return dp[i][heads];

    // Choice
    if(heads == 0) {
        // Return prob of tail only
        return (dp[i][heads] = Top_Down(i-1, heads)*(1-head_prob[i]));
    }
    else if(i > heads) {
        return (dp[i][heads] =
         Top_Down(i-1, heads-1)*head_prob[i] + Top_Down(i-1, heads)*(1-head_prob[i]));
    }
    
    return (dp[i][heads]=Top_Down(i-1, heads-1)*head_prob[i]);
}

void Bottom_Up() {
    dp[0][0] = 1;
    for(int j = 1; j <= n; ++j)
        dp[0][j] = 0;

    for(int i = 1; i <= n; ++i) {
        for(int heads = 0; heads <= n; ++heads) {
            if(heads == 0) dp[i][heads] = dp[i-1][heads]*(1-head_prob[i]);
            else if(i > heads) {
                dp[i][heads] = dp[i-1][heads-1]*head_prob[i] 
                                + dp[i-1][heads]*(1-head_prob[i]);
            }
            else dp[i][heads] = dp[i-1][heads-1]*head_prob[i];
        }
    }

    double total_prob = 0.0;
    for(int heads = n/2+1; heads <= n; ++heads) {
        total_prob += dp[n][heads];
    }

    cout << setprecision(10) << total_prob << endl;
}

int32_t main() {
    IOS;
    memset(dp, 0, sizeof(dp));
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> head_prob[i];
    }
    Bottom_Up();
}

Measured memory_bytes: 70656
N = int(input())
_A = list(map(int, input().split()))

#  偶数列
A = [a for a in _A if (a % 2 == 0)]
# 承認列
ans = [a for a in A if (a % 3 == 0 or a % 5 == 0)]

print("APPROVED" if len(A) == len(ans) else "DENIED")


Measured memory_bytes: 2940
N = int(input())
Dictionary = {}
for i in range(N):
    S = input()
    if S not in Dictionary :
        Dictionary[S] = 1
    else :
        Dictionary[S] = Dictionary[S]+1

sorted_Dic = sorted(Dictionary.items(), key=lambda x: x[1],reverse=True)

if len(sorted_Dic)==1:
  print(sorted_Dic[0][0])
else:
  ans_list = []
  for i in range(N):
      if sorted_Dic[i][1]==sorted_Dic[0][1]:
          ans_list.append(sorted_Dic[i][0])
      else:
          break;
  for item in sorted(ans_list):
    print(item)
    

Measured memory_bytes: 49872
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll a[N];
  ll ans = 0;
  for(int i = 0; i < N; ++i){
    cin >> a[i];
    if(a[i]%2 == 0){
      ll p = a[i];  
      while(p%2 == 0){
        ++ans;
        p /= 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define fr(i,start,end, inc) for(ll i=(start); i<(end); i+=inc)
#define rf(i,end,start, inc) for(ll i=(start-1); i>=(end); i-=inc)
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n; i++)
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define pl pair<ll, ll>
#define pi pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;

bool compare(const pl &a, const pl &b){
    return a.fi<b.fi || (a.fi==b.fi && a.se<b.se);
}
ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}
inline vector<ll> allinv(ll n, ll p){
    vector<ll> arr(n);
    arr[1]=1;
    fr(i,2,n,1){
        arr[i] = (p - (p/i)*arr[p%i]%p)%p;
    }
    return arr;
}
vector<ll> inline allncr(ll n, ll p){
    vector<ll> nci(n+1);
    nci[0]=1;
    nci[n]=1;
    vector<ll> v = allinv(n,p);
    fr(i,1,n,1){
        nci[i]=(nci[i-1]*(n-i-1))%p;
    }
    return nci;
}
ll max3(ll a, ll b, ll c){
    return max(max(a,b),c);
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

void prt(int i){   
    i ? cout << "YES\n" : cout << "NO\n" ;
}

template<class T>
void printv(T &v){
    ll n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}

bool check(ll a, ll b, ll c){
    if(a==-1 && b==-1 && c==-1)
        return true;
    return false;
}
int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        ll a[3][3];
        rep(i,3)
            rep(j,3)
                cin >> a[i][j];
        ll n,x;
        cin >> n;
        rep(i,n){
            cin >> x;
            rep(j,3){
                rep(k,3){
                    if(a[j][k]==x)
                        a[j][k]=-1;
                }
            }
        }
        bool poss=false;
        rep(i,3){
            if(check(a[i][0],a[i][1], a[i][2]))
                poss=true;
        }
        rep(i,3){
            if(check(a[0][i],a[1][i], a[2][i]))
                poss=true;
        }
        if(check(a[0][0], a[1][1], a[2][2]))
            poss=true;
        if(check(a[0][2], a[1][1], a[2][0]))
            poss=true;
        cout << (poss? "Yes\n":"No\n"); 
    }

}

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

int main(void) {
    int n,m,l;cin>>n>>m>>l;
    ll A[n][m],B[m][l];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ll tmp;cin>>tmp;
            A[i][j] = tmp;
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            ll tmp;cin>>tmp;
            B[i][j] = tmp;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            ll sum = 0;
            for (int k = 0; k < m; k++) {
                sum += A[i][k] * B[k][j];
            }
            cout << sum;
            if (j < l - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] lines = Console.ReadLine().Split(' ');
            int x = int.Parse(lines[0]);
            int y = int.Parse(lines[1]);
            int[] a = { 1, 3, 5, 7, 8, 10, 12 };
            int[] b = { 4, 6, 9, 11 };
            int[] c = { 2 };

            string ans = "";
            if (0 <= Array.BinarySearch(a, x) && 0 <= Array.BinarySearch(a, y))
            {
                ans = "Yes";
            }
            else if (0 <= Array.BinarySearch(b, x) && 0 <= Array.BinarySearch(b, y))
            {
                ans = "Yes";
            }
            else if (0 <= Array.BinarySearch(c, x) && 0 <= Array.BinarySearch(c, y))
            {
                ans = "Yes";
            }
            else
            {
                ans = "No";
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11220
n,a,b = gets.split.map(&:to_i)
s = gets.chomp
y = 0
x = 0
n.times{|i|
  if s[i]==?a
    if y<a+b
      puts "Yes"
      y += 1
    else
      puts "No"
    end
  elsif s[i]==?b
    if y<a+b&&x<b
      puts "Yes"
      y += 1
      x += 1
    else
      puts "No"
    end
  else
    puts "No"
  end
}


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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

const char ss[2][2] = {{'R', 'Y'}, {'G', 'B'}};

int main() {
	reg n = read(), m = read(), d = read();
	fo(i, 1, n) {
		fo(j, 1, m) {
			reg x = i + j - 2, y = i - j + m - 1;
			putchar(ss[(x / d) % 2][((y / d) % 2)]);
		} puts("");
	}
	return 0;
}



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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n, k, s[3];
    cin >> n >> k >> s[1] >> s[2] >> s[0];
    string t;
    cin >> t;
    int d[n];
    for(int i=0; i<n; i++){
        if(t[i]=='r') d[i]=0;
        else if(t[i]=='s') d[i]=1;
        else d[i]=2;
    }

    ll ans=0;
    bool win[n];
    fill(win, win+n, false);
    for(int i=0; i<n; i++){
        if(i<k){
            ans+=s[d[i]];
            win[i]=true;
        }else if(d[i]!=d[i-k]){
            ans+=s[d[i]];
            win[i]=true;
        }else if(i>=2*k && d[i]==d[i-2*k] && !win[i] && win[i-2*k]){
            ans+=s[d[i]];
            win[i]=true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll A,B;
	cin>>A>>B;
	if(A<10 && B<10){
		cout<<A*B;
	}else{
		cout<<"-1";
	}
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
if n%2==0:
  for i in range(n):
    if a[i]!=(i//2)*2+1:
      print(0)
      exit()
  print(pow(2,n//2,mod))
else:
  for i in range(n):
    if a[i]!=((i+1)//2)*2:
      print(0)
      exit()
  print(pow(2,n//2,mod))



Measured memory_bytes: 13940
def slove():
    import sys
    input = sys.stdin.readline
    w, h, n = list(map(int, input().rstrip('\n').split()))
    max_w = w
    max_h = h
    min_w = 0
    min_h = 0

    for i in range(n):
        x, y, a = list(map(int, input().rstrip('\n').split()))
        if a == 1:
            min_w = max(min_w, x)
        elif a == 2:
            max_w = min(max_w, x)
        elif a == 3:
            min_h = max(min_h, y)
        elif a == 4:
            max_h = min(max_h, y)
    if min_h >= max_h or min_w >= max_w:
        print(0)
    else:
        print((max_h - min_h) * (max_w - min_w))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;
ll IINF = INF*INF;

ll adj[110][110];
ll adjtmp[110][110];

void solve(){

    ll v,e;
    cin >> v >> e;
    rep(i,v){
        rep(j,v){
            adj[i][j]=IINF;
        }
    }
    rep(i,e){
        ll x,y,z;
        cin >> x >> y >> z;
        adj[x][y]=z;
        //adj[y][x]=z;
    }
    rep(i,v){
        adj[i][i]=0;
    }

    for (ll k = 0; k < v; k++){       // 経由する頂点
        for (ll i = 0; i < v; i++) {    // 始点
            for (ll j = 0; j < v; j++) {  // 終点
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    }

    rep(i,v){
        rep(j,v){
            adjtmp[i][j]=adj[i][j];
        }
    }

    for (ll k = 0; k < v; k++){       // 経由する頂点
        for (ll i = 0; i < v; i++) {    // 始点
            for (ll j = 0; j < v; j++) {  // 終点
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    }

    bool notnegativecycle = true;
    rep(i,v){
        rep(j,v){
            if(adjtmp[i][j]!=adj[i][j]) notnegativecycle = false;
        }
    }
    if(!notnegativecycle) {
        cout << "NEGATIVE CYCLE" << endl;
        return;
    }

    rep(i,v){
        rep(j,v){
            if(j==v-1){
                if(adj[i][j]<INF*100000) cout << adj[i][j];
                else cout << "INF";
            }
            else{
                if(adj[i][j]<INF*100000) cout << adj[i][j] << " ";
                else cout << "INF" << " ";
            }
        }
        cout << endl;
    }

}


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



Measured memory_bytes: 3364
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
       int a=sc.nextInt();
       int b=sc.nextInt();
       int c=sc.nextInt();
        System.out.println(c+" "+a+" "+b);
    }
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  ll ans=0;
  for(int i=k+1;i<=n;i++){
    ll num=(n+1)/i*i;
    if(k==0){num=n/i*i;}
    ans+=num/i*(i-k);
    if(k==0){ans+=max(0LL,((i-k)-(num+i-n)));}
else
    ans+=max(0LL,((i-k)-((num+i)-n-1)));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N, A, B, C, D = gets.chomp.split(' ').map(&:to_i)
S = (gets.chomp)[0 .. N]

Walks = 0.upto(S.size-2).map do |i|
    next -2 if S[i..i+1] == "##"
    next -1 if S[i..i+1] == "#."
    next  1 if S[i..i+1] == ".#"
    next  3 if S[i..i+2] == "..."
    2
end

def can_goal(start, goal)
    m = Walks[start-1 .. goal-2]

    return !m.any? { |i| i == -2 }
end

def can_wait(start, goal)
    m = Walks[start-1 .. goal-2]
    return true if S[start-2] == "." && S[start] == "."
    return false if m.any? { |i| i == -2 }
    return m.any? { |i| i == 3 }
end

pos  = C > D ? [ A, B ] : [ B, A ]
goal = C > D ? [ C, D ] : [ D, C ]

result = lambda do
    if pos[0] < pos[1]
        return false if not can_wait(pos[1], goal[1])
        return can_goal(pos[0], goal[0]) && can_goal(pos[1], goal[1])
    end
    if can_goal(pos[0], goal[0])
        return true if can_goal(pos[1], goal[1])
    end
    return false
end.call

puts result ? "Yes" : "No"


Measured memory_bytes: 4600
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
int read() {
	char cc = getchar(); int cn = 0, flus = 1;
	while(cc < '0' || cc > '9') {  if( cc == '-' ) flus = -flus;  cc = getchar();  }
	while(cc >= '0' && cc <= '9')  cn = cn * 10 + cc - '0', cc = getchar();
	return cn * flus;
}
const int N = 2e5 + 5 ; 
int a[N], sz, n, b[N] ; 
bool check( int x ) {
	rep( i, 1, sz ) b[i] = ( a[i] >= x ) ; 
	int wh1 = 0, wh2 = 0, b1, b2 ; 
	for( int k = 1; k < n; ++ k ) {
		if( ( b[n - k] == 0 && b[n - k + 1] == b[n - k] ) || ( b[n + k] == 0 && b[n + k - 1] == b[n + k] ) ) return 0 ; 
		if( ( b[n - k] == 1 && b[n - k + 1] == b[n - k] ) || ( b[n + k] == 1 && b[n + k - 1] == b[n + k] ) ) return 1 ; 
	}
	return b[1] ; 
} 
signed main()
{
	n = read() ; sz = 2 * n - 1 ; 
	rep( i, 1, sz ) a[i] = read() ;
	if( n == 1 ) { printf("%d\n", a[n] ) ; return 0; }
	int l = 1, r = sz, ans, mid ; 
	while( l <= r ) {
		mid = ( l + r ) >> 1 ; 
		if( check(mid) ) ans = mid, l = mid + 1 ; 
		else r = mid - 1 ;
	}
	printf("%d\n", ans ) ;
	return 0;
}

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

int f(int x) {
	int r = 0;
	for (; x; x /= 10) {
		r += x % 10;
	}
	return r;
}

int main() {
	int x;
	cin >> x;
	int y = f(x);
	cout << (x % y ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let s : Vec<char> = get_one::<String>().chars().collect();
    let mut t = String::new();
    for c in s {
        if c == 'B' {
            t.pop();
        }
        else {
            t.push(c);
        }
    }
    println!("{}", t);

}


Measured memory_bytes: 4352
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long N = long.Parse(Console.ReadLine());
        long max = 0;
        for(long i=1;i*i<=N;i++){
            if(N % i == 0){
                max = i;
            }
        }
        {
            long i = N/max;
            int count = 0;
            while(i > 0){
                i /= 10;
                count++;
            }
            sb.Append(count+"\n");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
vector<ll> V;
ll cnt[maxn];
int main() {
	ll sum=0;
    int n;cin>>n;
    for(int i=1;i<=n;i++) {
    	int tem;cin>>tem;cnt[tem]++;
    	sum+=tem;
    }
    int q;cin>>q;
    for(int i=1;i<=q;i++) {
    	ll a,b;cin>>a>>b;
    	sum-=cnt[a]*a;
    	sum+=cnt[a]*b;
    	cnt[b]+=cnt[a];
    	cnt[a]=0;
    	cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 4372
s = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'

a = list(s.split(','))
n = int(input())
print(a[n-1])

Measured memory_bytes: 38616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pli pair<ll, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pq priority_queue;

void bfs(int i, vector<int> *v, vector<bool> &vis, vector<int> &next)
{
	queue<int> q;
	q.push(i);
	vis[i]=1;
	while(!q.empty())
	{
		int j=q.front();
		q.pop();
		ll l=v[j].size();
		lp(i,0,l)
		{
			if(!vis[v[j][i]])
			{
				next[v[j][i]]=j;
				q.push(v[j][i]);
				vis[v[j][i]]=1;
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	vector<int> v[n+1];
	vector<bool> vis(n+1, 0);
	vector<int> next(n+1, 0);
	lp(i,0,m)
	{
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	bfs(1,v,vis,next);
	lp(i,1,n+1)
	{
		if(!vis[i])
		{
			cout<<"No\n";
			exit(0);
		}
	}
	cout<<"Yes\n";
	lp(i,2,n+1)
		cout<<next[i]<<"\n";
	return 0;
}

Measured memory_bytes: 10260
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		boolean[] a=new boolean[5];
		for (int i=0;i<5;++i) {
			int x=sc.nextInt();
			if (x==0) continue;
			a[x-1]=true;
		}
		for (int i=0;i<5;++i) if (!a[i]) System.out.println(i+1);
	}

	void tr(Object...o) {System.out.println(Arrays.deepToString(o));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
        	ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 32456
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

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

int main() {
  int k,a,b;cin>>k>>a>>b;
  while (a < b+1) {
    if (a%k == 0) {
      cout<<"OK";
      return 0;
    } 
    a++;
  }
  cout<<"NG";
}


Measured memory_bytes: 3632
'use strict'

function solve(N, P) {
  var dp = new Array(N+1).fill(0).map(e => new Array(N+1).fill(0))
  for (var i = 0; i < dp.length; i++) {
    for (var j = 0; j < dp[i].length; j++) {
      if (i === 0 && j === 0) {
        dp[i][j] = 1
        continue
      }
      if (j > i) {
        dp[i][j] = 0
      } else if (j === i) {
        dp[i][j] = P[i-1] * dp[i-1][j-1]
      } else if (j < i) {
        if (j === 0) {
          dp[i][j] = (1-P[i-1]) * dp[i-1][j]
        } else {
          dp[i][j] = P[i-1] * dp[i-1][j-1] + (1-P[i-1]) * dp[i-1][j]
        }
      }
    }
  }
  var startIndex = parseInt(N/2) + 1
  var res = 0
  for (var i = startIndex; i < dp[N].length; i++) {
    res += dp[N][i]
  }
  return res
}

function main(input) {
  var lines = input.split("\n")
  var N = parseInt(lines[0])
  var P = lines[1].split(' ').map(l => parseFloat(l))
  var ans = solve(N, P)
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 181040
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  int n; cin >> n;

  vector<ll> a(n), b(n), c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));

  vector<ll> x(n);
  rep(i, n) {
    auto itr = lower_bound(ALL(a), b[i]);
    if (itr == a.begin()) {
      x[i] = 0;
    } else {
      x[i] = itr - a.begin();
    }
  }

//  rep(i, n) cerr << x[i] << " "; cerr << endl;

  vector<ll> s(n, 0);
  s[0] = x[0];
  for (int i = 0; i < n-1; i++) {
    s[i+1] = s[i] + x[i+1];
  }

//  rep(i, n) cerr << s[i] << " "; cerr << endl;

  ll ans = 0;
  rep(i, n) {
    auto itr = lower_bound(ALL(b), c[i]);
    if (itr == b.begin()) continue;
    int idx = itr - b.begin() - 1;
//    cerr << idx << " " << s[idx] << endl;
    ans += s[idx];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <sstream>

/*
auto ans(int n, int y) -> std::string
{
    std::stringstream ss;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            auto tmp = y - (i * 1000 + j * 5000);
            auto remain = n - i - j;
            if(remain < 0)
            {
                break;
            }

            tmp -= remain * 10000;
            if(tmp == 0)
            {
                ss
                    << remain <<  " "
                    << j << " "
                    << i << " ";
                return ss.str();
            }
        }
    }
    return "-1 -1 -1";
}
*/

auto simple(int n, int y) -> std::string
{
    std::stringstream ss;
    for(int i=0; i <= n; ++i)
    {
        for(int j=0; j <= (n - i); ++j)
        {
            auto rem = n - i - j;
                if(i * 10000 + j * 5000 + rem * 1000 == y)
                {
                    ss << i << " "
                        << j << " "
                        << rem << " ";
                    return ss.str();
                }
        }
    }
    return "-1 -1 -1";
}

int main(int argc, char const* argv[])
{
    int n, y;
    std::cin >> n >> y;

    /* auto a0 = ans(n, y); */
    auto a1 = simple(n, y);

    /* std::cout << a0 << std::endl; */
    std::cout << a1 << std::endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

string cmp(string a,string b){
    if(a.size()==b.size())return a<b?b:a;
    else return a.size()<b.size()?b:a;
}

int main(){
	int n;
	vi d={0,362880,40320,5040,720,120,24,6,2,1,1,};
	while(cin>>n,n){
        vs s(n);
        map<char,int> mp;
        set<char> st;
        rep(i,n) {
            cin>>s[i];
            if(s[i].size()!=1)st.insert(s[i][0]);
            int d=1,pref=(i+1==n)?-1:1;
            for(int j=s[i].size()-1;j>=0;j--){
                if(mp.find(s[i][j])==mp.end()){
                    mp[s[i][j]]=0;
                }
                mp[s[i][j]]+=pref*d;
                d*=10;
            }
        }
        string c="";
        vlai x(0,10);
        int lp=0;
        for(auto p:mp){
            c+=p.fs; x[lp++]=p.sc;
        }
        vlai p(10); iota(begin(p),end(p),0);
        
        int ans=0;
        do{
            //ans+=(p*x).sum()==0;
            if(st.find(c[find(begin(p),end(p),0)-begin(p)])!=st.end()) continue;
            if((p*x).sum()==0){
                ans++;
                //cout<<c[find(begin(p),end(p),0)-begin(p)];rep(i,10)cout<<p[i];cout<<endl;
            }
        }while(next_permutation(begin(p),end(p)));
        cout<<ans/d[mp.size()]<<endl;
	}
	return 0;
}



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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
ans = 0
for i in range(1, N+1, 2):
    if len(make_divisors(i)) == 8:
        ans += 1
print(ans)

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

//create arrays outside of main()
int a[50] = {};

int main()
{

    long long a, b;
    cin >> a >> b;

    if (a >= 0 && b <= 0 || a <= 0 && b >= 0)
    {
        cout << "Zero";
    }
    else if (a >= 0 && b >= 0)
    {
        cout << "Positive";
    }
    else if (a < 0 && b < 0)
    {
        int remain = (abs(a - b) + 1) % 2;
        if (remain == 1)
        {
            cout << "Negative";
        }
        else
        {
            cout << "Positive";
        }
    }

    return 0;
}

Measured memory_bytes: 256
'use strict'

function solve(N, A) {
  var dp = new Array(N+1).fill(0).map(e => new Array(N+1).fill(0))
  var row = 1
  var col = 1
  while (col <= N) {
    var c = col
    for (var r = row; r <= N; r++) {
      if (c > N) {
        break
      }
      if (c === r) {
        dp[r][c] = A[r-1]
      } else if (c === (r+1)) {
        dp[r][c] = Math.max(A[r-1], A[c-1])
      } else {
        dp[r][c] = Math.max(A[r-1] + Math.min(dp[r+1][c-1], dp[r+2][c]), A[c-1] + Math.min(dp[r+1][c-1], dp[r][c-2]))
      }
      c++
    }
    col++
  }
  var taro = dp[1][N]
  var sum = A.reduce((acc, current) => acc + current)
  return taro - (sum - taro)
}

function main(input) {
  var lines = input.split("\n")
  var N = parseInt(lines[0])
  var A = lines[1].split(' ').map(l => parseInt(l))
  var ans = solve(N, A)
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(void) {
  int N;
  scanf("%d", &N);
	int x = 1;
	int y;
	int i;
	char *S;
	int a[4] = {0};
	S = (char *)malloc(N * sizeof(char));
	
	for(i=0; i<N; i++) {
		scanf("%s", &S[i]);
	}

	
	for(i=0; i < N; i++) {
		switch(S[i]) {
			case('P'):
				a[0] = 1;
				break;
			case('W'):
				a[1] = 1;
				break;
			case('G'):
				a[2] = 1;
				break;
			case('Y'):
				a[3] = 1;
				break;
			default:
				printf("ERROR!\n");
				return 0;
		}
	}
	if(a[0] + a[1] + a[2] + a[3] == 4){
		printf("Four\n");
		free(S);
		return 0;
	}
	printf("Three\n");
		free(S);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll A,B;cin>>A>>B;
  ll g=__gcd(A,B);
  vector<ll> divs,ans;
  for(ll i=1;i<=sqrt(g);i++)
  {
      if(g%i ==0)
        {
           // cout<<i<<" divides ";
            divs.push_back(i);
        }
      ll b=g/i;
      if(g%b==0 && b!=i)
      {
          //cout<<b<<" divides ";
          divs.push_back(b);
      }
  }
  sort(divs.begin(),divs.end());
  for(int i=0;i<divs.size();i++)
  {
      bool good=true;
      for(int j=0;j<ans.size();j++)
      {
          if(i!=j && __gcd(divs[i],ans[j])!=1) {good=false; break;}
      }
      if(good) ans.push_back(divs[i]);
  }
  cout<<ans.size();
  return 0;
}


Measured memory_bytes: 384
// ALDS1_7_B.cpp
// Tree - Binary Trees

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

struct Node
{
	int id;
	int parent = -1;
	int sibling = -1;
	int degree = 0;
	int depth = 0;
	int height = 0;
	string type = "internal node";
};

int main()
{
	int n;
	cin >> n;
	vector<Node> nodes(n);
	for (int i = 0; i < n; i++) {
		int idx, left, right;
		cin >> idx >> left >> right;
		nodes[idx].id = idx;
		if (left != -1) {
			nodes[left].parent = idx;
			nodes[idx].degree++;
			if (right != -1) {
				nodes[left].sibling = right;
				nodes[right].sibling = left;
			}
		}
		if (right != -1) {
			nodes[right].parent = idx;
			nodes[idx].degree++;
		}
		if (!nodes[idx].degree) nodes[idx].type = "leaf";
	}

	for (int i = 0; i < n; i++) {
		int j = i;
		while (nodes[j].parent != -1) {
			int child_h = nodes[j].height;
			j = nodes[j].parent;
			nodes[j].height = max(nodes[j].height, child_h + 1);
			nodes[i].depth++;
		}
		if (!nodes[i].depth) nodes[i].type = "root";
	}

	for (int i = 0; i < n; i++) {
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
			nodes[i].id, nodes[i].parent, nodes[i].sibling, nodes[i].degree, nodes[i].depth,
			nodes[i].height);
		cout << nodes[i].type << endl;
	}
	return 0;
}

Measured memory_bytes: 3268
N,M=map(int, input().split())
inlist = [tuple([int(st) for st in input().split()]) for i in range(M)]
inlist.sort()

res=0
minright=100000000000
for fr, to in inlist:
    if to < minright:
        minright = to
    if minright <= fr:
        res += 1
        minright = to
    # print("minr: {}".format(minright))

print(res+1)


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

int main() {
    int n; cin >> n;
    vector<int> a(200010);
    vector<int> ans(200010);
    for (int i = 2; i <= n; i++) cin >> a[i];
    for (int i = 2; i <= n; i++) ans[a[i]]++;
    for (int i = 1; i <= n; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4848