akhauriyash/Code-Regression huggingface dataset:
/*
[caddi2018] E - Negative Doubling
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 200000;
const int K = 16;

int N;
ll A[MAX_N];
ll dp0[MAX_N][K], dp1[MAX_N][K];

ll solve() {
    for (int k = 0; k < K; k++) {
        dp0[N - 1][k] = k;
        dp1[0][k] = k;
    }

    for (int i = N - 2; i >= 0; i--) {
        ll k4 = 1;
        for (int k = 0; k < K; k++) {
            int j = 0;
            ll j4 = 1;
            while (A[i] * k4 > A[i + 1] * j4) {
                j++;
                j4 *= 4;
            }
            if (j <= 15) {
                dp0[i][k] = dp0[i + 1][j] + k;
            } else {
                dp0[i][k] = dp0[i + 1][15] + (N - i - 1) * (j - 15) + k;
            }

            k4 *= 4;
        }
    }

    for (int i = 1; i < N; i++) {
        ll k4 = 1;
        for (int k = 0; k < K; k++) {
            int j = 0;
            ll j4 = 1;
            while (A[i - 1] * j4 < A[i] * k4) {
                j++;
                j4 *= 4;
            }
            if (j <= 15) {
                dp1[i][k] = dp1[i - 1][j] + k;
            } else {
                dp1[i][k] = dp1[i - 1][15] + i * (j - 15) + k;
            }

            k4 *= 4;
        }
    }

    ll ans = dp0[0][0] * 2;
    for (int i = 1; i < N; i++) {
        ans = min(ans, i + dp1[i - 1][0] * 2 + dp0[i][0] * 2);
    }

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 51840
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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 MOD = 1000000007;
const int MAX = 2000100;
long long fac[MAX], finv[MAX], inv[MAX];
void init_comb() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long comb(int n, int r) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

template< int mod >
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(long long n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    long long t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
using mint = ModInt< MOD >;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init_comb();
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  --r1, --c1;
  mint ans = (mint)comb(r2+c2+2, r2+1)-1;
  ans -= (mint)comb(r1+c2+2, r1+1)-1;
  ans -= (mint)comb(r2+c1+2, r2+1)-1;
  ans += (mint)comb(r1+c1+2, r1+1)-1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 47104
use proconio::input;

fn main() {
    input!(n: usize, k: usize, a: [proconio::marker::Usize1; n]);
    let mut cnt = vec![0; n];
    a.iter().for_each(|&x| cnt[x] += 1);
    let mut cnt: Vec<_> = cnt.iter().filter(|&&x| x != 0).collect();
    cnt.sort_by_key(|x| std::cmp::Reverse(*x));
    println!(
        "{}",
        if k < cnt.len() {
            cnt[k..].iter().copied().copied().sum::<usize>()
        } else {
            0
        }
    );
}


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

int main(){ 
  int a, b, Min, Max, ans;
  cin >> a >> b;
  
  Min = min(a,b);
  Max = max(a,b);
  
  ans = 0;
  
  rep(i,Max) {
    ans = ans * 10 + Min;
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << std::fixed << std::setprecision(10);

	int n, k;
	cin >> n >> k;
	int r, s, p;
	cin >> r >> s >> p;
	string t;
	cin >> t;

	vector<vector<int>> dp(n, vector<int>(3, 0));

	for (int i = 0; i < n; i++) {
		if (i < k) {
			if (t[i] == 'r') {
				dp[i][2] += p;
			}
			else if (t[i] == 's') {
				dp[i][0] += r;
			}
			else {
				dp[i][1] += s;
			}
		}
		else {
			dp[i][0] = max(dp[i - k][1], dp[i - k][2]);
			dp[i][1] = max(dp[i - k][0], dp[i - k][2]);
			dp[i][2] = max(dp[i - k][0], dp[i - k][1]);
			if (t[i] == 'r') {
				dp[i][2] += p;
			}
			else if (t[i] == 's') {
				dp[i][0] += r;
			}
			else {
				dp[i][1] += s;
			}

		}
	}

	int ans = 0;
	for (int i = n - k; i < n; i++) {
		ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5840
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
count = len(C)
for i, j in enumerate(A):
  ans += B[j - 1]
  if i < count and A[i] + 1 == A[i+1]: 
    ans += C[j - 1]
print(ans)

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

int main(){
    int n,k;
    cin >> n >> k;
    int ans=0;
    int x[100];
    for(int i=0;i<n;i++){
        cin >> x[i];
        ans+=min(abs(x[i]),abs(k-x[i]));
    }
    cout << ans*2 << endl;
}

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

void solve(int A,int B){
  double vA,vB;
  long long c;
  long long ans = 0LL;
  for(long long i = A/2;i > 0;--i){
    vA = double(A)/i;
    vB = double(B)/i;
    if(int(vA) == vA && int(vB) == vB){
      c = i;
      break;
    }
  }
  long long a = A;
  long long b = B;
  cout << a * b / c;
}
int main() {
  int A, B;cin >> A >> B;
  if(A > B)
    solve(A,B);
  else
    solve(B,A);
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int N,A,B;
	cin >> N >> A >> B;
	int c[3]={};
	for(int i=0;i<N;i++){
		int p;
		cin >> p;
		if(p<=A){
			c[0]++;
		}
		else if(p>=B+1){
			c[2]++;
		}
		else{
			c[1]++;
		}
	}
	cout << min(min(c[0],c[1]),c[2]) << endl;

	return 0;
}



Measured memory_bytes: 256
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for modular inverse
ll inv(ll a,ll m){
	return mpow(a,m-2,m);
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

// Utility for binomial coefficient
ll ncr(ll n,ll k)
{
    if(n<k)
        return 0;
    ll C[n + 1][k + 1];
    ll i,j;
    for(i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if (j==0 || j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    return C[n][k];
}

void solve(){
	//code
	int n,m;
	cin>>n>>m;
	if(n==m) cout<<"Yes";
	else cout<<"No";
}

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


Measured memory_bytes: 3604
#include<stdio.h>

int main()
{
    long long m, n;
    scanf("%lld %lld", &m, &n);

    long long x = m, y = n, z = 1;

    for( ; y; y >>= 1){
        if(y & 1){ z = (z * x) % 1000000007; }
        x = (x * x) % 1000000007;
    }
    printf("%lld\n", z);
 
    return 0;
}

Measured memory_bytes: 1028
import numpy as np
n = int(input())
hikumono = n * (n-1)//2
A = np.array(list(map(int, input().split())))
B = np.array([i+1 for i in range(n)])
C=A-B
heikin1 = int(np.median(C))
heikin2 = heikin1 + 1
heikin3 = heikin1 - 1
ans1 = abs(C-heikin1).sum()
ans2 = abs(C-heikin2).sum()
ans3 = abs(C-heikin3).sum()
print(min(ans1, ans2, ans3))

Measured memory_bytes: 34184
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
ret = max([sum(a1[0:i+1])+sum(a2[i::]) for i in range(n)])
print(ret)

Measured memory_bytes: 3060
import std.stdio,std.string,std.conv;

int main()
{
	double a[10];
	string s;
	while((s = readln.chomp).length != 0)
	{
		double n = s.to!double;
		double ans = 0;
		a[0] = n;

		foreach(i;1..10)
		{
			if((i+1)%2 == 0)
			{
				a[i] = a[i-1]*2;
			}
			else
			{
				a[i] = a[i-1]/3;
			}
		}

		foreach(i;0..10)
		{
			ans += a[i];
		}

		writefln("%.8f",ans);
	}
	return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int M=924844033;
int N,K;
int dp[2][2][2020][2020];
inline void add(int &a,int b)
{
	a+=b;
	if(a>=M)a-=M;
}
void calcdp()
{
	//no first
	dp[0][1][0][0]=1;
	for(int len=1;len<=N;len++)
	{
		for(int mch=0;mch<len;mch++)
		{
			// no move
			add(dp[0][0][len][mch],dp[0][0][len-1][mch]);
			add(dp[0][0][len][mch],dp[0][1][len-1][mch]);
			
			//move left
			add(dp[0][0][len][mch+1],dp[0][0][len-1][mch]);
			
			//move right
			add(dp[0][1][len][mch+1],dp[0][0][len-1][mch]);
			add(dp[0][1][len][mch+1],dp[0][1][len-1][mch]);
		}
	}
	
	//has first
	dp[1][0][0][0]=1;
	for(int len=1;len<=N;len++)
	{
		for(int mch=0;mch<len;mch++)
		{
			// no move
			add(dp[1][0][len][mch],dp[1][0][len-1][mch]);
			add(dp[1][0][len][mch],dp[1][1][len-1][mch]);
			
			//move left
			add(dp[1][0][len][mch+1],dp[1][0][len-1][mch]);
			
			//move right
			add(dp[1][1][len][mch+1],dp[1][0][len-1][mch]);
			add(dp[1][1][len][mch+1],dp[1][1][len-1][mch]);
		}
	}
}
bool vis[2020];
int ans[2020],tmp[2020],cur[2020],ansLen;
void combineans(int len,int fst,int lst)
{
	for(int cc=0;cc<=len;cc++)
	{
		cur[cc]=dp[fst][0][len][cc];
		if(lst)add(cur[cc],dp[fst][1][len][cc]);
	}
//	cout<<fst<<" "<<lst<<" "<<len<<endl;
	for(int cc=0;cc<=len;cc++)
	{
//		cout<<cur[cc]<<endl;
	}
//	system("pause");
	memset(tmp,0,sizeof(tmp));
	for(int mch=0;mch<=ansLen+len;mch++)
	{
		for(int cc=max(0,mch-ansLen);cc<=len;cc++)
		{
			add(tmp[mch],cur[cc]*1ll*ans[mch-cc]%M);
//			cout<<mch<<" "<<cc<<" "<<cur[cc]<<" "<<ans[mch-cc]<<" "<<tmp[mch]<<endl;
		}
	}
	for(int mch=0;mch<=ansLen+len;mch++)
		ans[mch]=tmp[mch];
	ansLen+=len;
//	system("pause");
}
int main()
{
	cin>>N>>K;
	calcdp();
	ans[0]=1;
	ansLen=0;
	for(int pos=1;pos<=N;pos++)
	{
		if(vis[pos])continue;
		int cnt=0;
		for(int i=pos;i<=N;i+=K*2)
		{
			vis[i]=1;
			cnt++;
		}
		bool fst=(pos-K)>=1;
		bool lst=(pos+(cnt-1)*K*2+K)<=N;
		combineans(cnt,fst,lst);
	//	for(int i=0;i<=ansLen;i++)
	//		cout<<i<<" "<<ans[i]<<endl;
	//	system("pause");
	}
	int fac=1;
	if(N&1)fac=(M-fac);
	int res=0;
	for(int inK=N;inK>=0;inK--)
	{
	//	cout<<inK<<" "<<ans[inK]<<" "<<fac<<endl;
	//	system("pause");
		add(res,fac*1ll*ans[inK]%M);
		fac=fac*1ll*(N-inK+1)%M;
		fac=M-fac;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 62976
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	n := scanText()
	ok := strings.Contains(n, "7")
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {
	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}

func fact(n int) int {
	ret := 1
	for i := 1; i <= n; i++ {
		ret *= i
	}
	return ret
}

func isPrimeNum(n int) bool {

	if n <= 1 {
		return false
	}

	l := int(math.Sqrt(float64(n)) + 1.)
	for i := 2; i < l; i++ {
		if n%i == 0 {
			return false
		}
	}

	return true
}


Measured memory_bytes: 1756
from math import gcd
N,M=list(map(int, input().split()))
S=input()
T=input()
g=gcd(N,M)
l=N*M//g
n=l//N
m=l//M
for i in range(0,l,n):
  if i%m==0:
    if S[i//n]!=T[i//m]:
      print(-1)
      exit()
else:
  print(l)

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


int main(){

    int n;
    scanf("%d",&n);

    int a[n];
    int i;
    int max=0;
    for(i = 0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[max]<a[i])max=i;
    }

    int sum=0;
    for(i=0;i<n;i++){
        if(i!=max)sum=sum+a[i];
    }
    if(sum<=a[max])printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){

  int A, B;
  cin >> A >> B;

  if(B==1){
  	cout << 0 <<endl;
  	return 0;
  }

  cout << ((B-1)-1)/(A-1)+ 1 <<endl;
  
  return 0;
}




Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
$s=trim(fgets(STDIN));
$i=1;
$c=$s[0];
$ans=1;
while($i<$n){
  if($s[$i]!=$c){
    ++$ans;
    $c=$s[$i];
  }
  ++$i;
}
echo $ans;

Measured memory_bytes: 4856
#define scanf_s scanf

#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <iostream>
using namespace std;
int saiki(int, int);
int n, A[20], m, q[200] = { 0 }, x;
int main(void)
{
	scanf_s("%d", &n);
	for (int i = 0; i < n; i++) { scanf_s("%d", &A[i]); }
	scanf_s("%d", &m);
	for (int i = 0; i < m; i++) {
		scanf_s("%d", &x);
		q[i] = saiki(0, 0);
	}
	for (int i = 0; i < m; i++) {
		if (q[i]) { printf("yes\n"); }
		else { printf("no\n"); }
	}
}
int saiki(int s, int l)
{
	for (int i = l; i < n; i++) {
		if (A[i] + s == x) { return 1; }
		if (A[i] + s < x) { 
			if (saiki(A[i] + s, i + 1)) return 1;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, k, q; cin >> n >> k >> q;
	vector<int> a(q);
	rep(i, q)cin >> a[i];
	vector<int> pl(n);
	rep(i, n)pl[i] = k - q;

	rep(i, q) {
		pl[a[i]-1]++;
	}

	

	rep(i, n) {
		puts(pl[i] > 0 ? "Yes" : "No");
	}
	return 0;
}

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

const int MAX = 30000;
int main() {
	int N;
	cin >> N;
	int sum = 0;
	if (N == 3) cout << "2 5 63";
	else {
		N -= 4;
		cout << "2 3 4 9";
		for (int i = 8;i <= MAX&& N >= 2;i += 6) {
			cout << " " << i << " " << i + 2;
			N -= 2;
		}
		for (int i = 15;i <= MAX && N >= 2;i += 12) {
			cout << " " << i << " " << i + 6;
			N -= 2;
		}
		for (int i = 6;i <= MAX && N >= 1;i += 6) {
			cout << " " << i;
			N --;
		}
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

N≦20000なのにa_i≦30000なので、値は結構近いことが予想されるね
というか半分以上は数字の差が1しかないね
つまり、それでも構築できるような方法がある訳だ

まず、鳩の巣原理より確実に一つ以上の偶数と3の倍数は含まれる
そこで、全て偶数と3の倍数にすると、15000個の偶数と10000個の3の倍数、5000個の6の倍数を考えて20000個構築できるね
10000個の6の倍数で無い偶数、5000個の6の倍数でない3の倍数、5000個の6の倍数で20000個ね
ちなみに偶数の内訳として、4の倍数は5000個、4の倍数でない2の倍数は5000個
さて、これでおｋなのか？考えてみよう
要素に2と3は含まれる、ということは最大公約数は1
総和は6の倍数
お、勝った
後は順に4の倍数と4の倍数で無い偶数、あるいは2個の3の倍数、あるいは1個の6の倍数を省いても条件を満たすので
*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define mod 1000000007
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = INF;
    rep(i, s.size() - t.size() + 1) {
        int cnt = 0;
        rep(j, t.size()) {
            if (s[i + j] != t[j]) {
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    if (ans == INF) cout << 0 << endl;
    else cout << ans << endl;
}

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

int N = 10010;
int M,A[10010],B[10010],COST[10010];
pair<int,int> bridge[10010]; //コストと橋番号のペア
int P[10010]; //0から10000までの取り扱い可能
void init(int N) { //初期化　初めは全ての頂点はバラバラ
  for (int i = 0; i < N; ++i) P[i] = i;
  }
 
 int root(int a) { //aのroot(代表元)を求める
   if (P[a] == a) return a; //aはroot
   return (P[a] = root(P[a])); //aの親のrootを求め、aの親とする
  }
  bool is_same_set(int a, int b){ //aとbが同じグループに属するか?
    return root(a) == root(b);
	}
  void unite(int a, int b) { //aとbを同一グループにまとめる
    P[root(a)] = root(b);
	}
	
int main(){
  while(cin >> N >> M && (N>0)){
 //(NとMを読み込み,Nが0より大きければ処理する)
    init(N);
	int sum = 0;
    for (int i=0; i<M; ++i) {
	  //A[i]とB[i]とCOST[i]を読み込む
	  cin >> A[i] >> B[i] >> COST[i];
	  bridge[i].first = COST[i];
	  bridge[i].second = i;
	  }
	   //コストの小さい順に整列
	  sort(bridge, bridge+M);
  for (int i=0; i<M; ++i) {
    int cost = bridge[i].first;
	int a = A[bridge[i].second];
	int b = B[bridge[i].second];
	//「aからbにcostの橋がかかっている」と表示
	for (int i=0; i<M; ++i){ //安い橋から順に
	if (!is_same_set(a,b)){ //(端の両端の節点が既に連結だったら)
	//端の両端の節点を同一グループに併合する
	unite (a,b);
	//合計に,橋のコストを加える
	sum += cost;
	  }
	 }
	}
	//合計を出力
	cout << sum << endl;
 }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

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

  int x,y,a,b,c; cin >> x >> y >> a >> b >> c;
  vector<int> red(a);
  vector<int> green(b);
  vector<int> less(c);
  rep(i, a) cin >> red[i];
  rep(i, b) cin >> green[i];
  rep(i, c) cin >> less[i];
  sort(red.begin(), red.end(), greater<int>());
  sort(green.begin(), green.end(), greater<int>());
  sort(less.begin(), less.end(), greater<int>());

  ll ans = 0;
  vector<int> added(x+y);
  rep(i, x) {
    ans += red[i];
    added[i] = red[i];
  }
  rep(i, y) {
    ans += green[i];
    added[x+i] = green[i];
  }
  sort(added.begin(), added.end());

  int added_i = 0;
  rep(i, c) {
    if(less[i] > added[i]) {
      ans += less[i] - added[i];
    } else {
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
ll MOD = 1000000007;
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main()
{   
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll res = 0;
    rep(i,n){
        res += a[i]-1;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace AtCoder {
    class Program {
        static void Main(string[] args) {

            var n = int.Parse(Console.ReadLine());
            var list = new int[n];
            for(int i = 0; i < n; i++) {
                list[i] = int.Parse(Console.ReadLine());
            }
            var a = (list.Max()) / 2;
            var b = list.OrderByDescending(x => x).Skip(1).Sum();

            Console.WriteLine(a + b);
        }
    }
}

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

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

    int l,r;
    cin>>l>>r;

    int z;
    bool flag=false;
    z=(r-l+1)/2019;

    l%=2019;
    r%=2019;
    if(r<=l)
        r+=2019;

    if(z>=1)
    {
        r+=2019;
    }

    int mn=1e9;
        for (int i = l; i <= r; ++i) {
            for (int j = i + 1; j <= r; ++j) {
                mn = min(mn, (i * j) % 2019);
            }
        }

    cout<<mn;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  cout << (a + b) % 24 << '\n';
}

Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI = 3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
	cini(a);
	cini(b);
	if (a > b)
		swap(a, b);
	int ans = 0;
	if (a == 1 && b == 2)
		ans = 3;
	else if (a == 1 && b == 3)
		ans = 2;
	else
		ans = 1;

	cout << ans << endl;
}

int main() {
	cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	solve();
}



Measured memory_bytes: 256
n,m = map(int,input().split())
aci = [0]*n
wai = [0]*n
ac = 0
wa = 0
for i in range(m):
    p,s = map(str,input().split())
    p = int(p)
    if s == "WA": wai[p-1] += 1
    elif s == "AC" and aci[p-1] == 0:
        aci[p-1] += 1
        ac += 1
        wa += wai[p-1]
print(ac,wa)

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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%2lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long double ld;

int ans;
int N;
ld x[10], y[10];
vector<int> p;



int main(void) {
    scanf("%d", &N);
    rep(i, 0, N) {
      scanf("%Lf %Lf", &x[i], &y[i]);
    }

    rep(i, 0, N) p.pb(i);

    ld sum = 0;
    int c = 0;
    do {
      per(i, 1, p.size()) {
        ld t = (x[p[i]]-x[p[i-1]])*(x[p[i]]-x[p[i-1]])+(y[p[i]]-y[p[i-1]])*(y[p[i]]-y[p[i-1]]);
        sum += sqrt(t);
      }
      c++;

    } while (next_permutation(p.bg, p.en));
  
    printf("%0.10Lf\n", sum / c);

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void Today(int d){
  if(d%7==1) printf("Thursday\n");
  else if(d%7==2) printf("Friday\n");
  else if(d%7==3) printf("Saturday\n");
  else if(d%7==4) printf("Sunday\n");
  else if(d%7==5) printf("Monday\n");
  else if(d%7==6) printf("Tuesday\n");
  else printf ("Wednesday\n");
}

int main(void){
  int m,d;
  while(1){
    scanf("%d %d",&m,&d);
    if(m==0 && d==0) break;

    while(m-->0){
      switch(m){
        case 2:
          d+=29;
          break;
        case 1:case 3:case 5:case 7:case 8:case 10:case 12:
          d+=31;
          break;
        case 4:case 6:case 9:case 11:
         d+=30;
         break;
      }
    }
    Today(d);
  }
  return 0;
}



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

using namespace std;

int n;

int main(){
    int a[]={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};
    scanf("%d",&n);
    printf("%d\n",a[n-1]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

struct point
{
	double x, y;
	point(double x = 0, double y = 0) :x(x), y(y) {};
	
	point operator + (point p) { return point(x + p.x, y + p.y); }
	point operator - (point p) { return point(x - p.x, y - p.y); }
	point operator * (double s) { return point(x * s, y * s); }
	point operator / (double s) { return point(x / s, y / s); }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }

	bool operator < (const point &p) const
	{
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const point &p) const
	{
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

};

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

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

int ccw(point a, point b, point c)
{
	b = b - a; c = c - a;
	if (cross(b, c) > EPS) return 1;//???????¨????????????????a,b,c??¨?????¶
	if (cross(b, c) < -EPS) return -1;//???????¨????????????????a,c,b??¨?????¶
	if (dot(b, c) < 0) return 2;//??´?????????c,a,b??????????????¶
	if (b.norm() < c.norm()) return -2;//??´?????????a,b,c??????????????¶
	return 0;//??´?????????a,c,b??????????????¶
}


int main()
{
	double p[4];
	REP(i, 4) cin >> p[i];
	point a(p[0], p[1]);
	point b(p[2], p[3]);
	int q; cin >> q;
	while (q--)
	{
		double x, y;
		cin >> x >> y;
		point c(x, y);
		int ans = ccw(a, b, c);
		string s;
		switch (ans)
		{
		case -2:
			s = "ONLINE_FRONT";
			break;
		case -1:
			s = "CLOCKWISE";
			break;
		case 0:
			s = "ON_SEGMENT";
			break;
		case 1:
			s = "COUNTER_CLOCKWISE";
			break;
		case 2:
			s = "ONLINE_BACK";
			break;
		}
		cout << s << endl;
	}
	return 0;
}

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

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

    while (a + 2 <= b || a + 2 <= c)
        a += 2, ans++;
    while (b + 2 <= a || b + 2 <= c)
        b += 2, ans++;
    while (c + 2 <= b || c + 2 <= a)
        c += 2, ans++;

    if (a > b)
        swap(a, b);
    if (a > c)
        swap(a, c);
    if (b > c)
        swap(b, c);

    if (a == c) {
        // nothing
    }
    else if (a == b)
        ans++;
    else
        ans += 2;

    cout << ans << '\n';
    return 0;
}


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define REP(i, n) for (int i = 0; i < (n); i++)

int main(int argc, char const *argv[])
{
    int N; cin >> N;
    int d[201] = {};
    int ans = 0;
    for (int i = 1; i <= N; i+=2) {
        for (int j = 1; j <= i; j++) {
            if (i%j == 0) d[i]++;
        }
        if (d[i] == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
bool ispalin(string s){
	int i =0 ,j = s.size()-1;
	while(i<=j && s[i]==s[j])i++,j--;
	return i>j;
}
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		string s;
		cin>>s;
		int n = s.size();
		int f =1;
		if(!(ispalin(s))){
			f=0;
		}
		int i = 0;
		int j = (n-1)/2;
		string a;
		for(;i<j;i++)a+=s[i];
		if(!(ispalin(a)))f=0;
		i =(n+3)/2-1;
		j = n;
		a.clear();

		for(;i<j;i++)a+=s[i];
		if(!(ispalin(a)))f=0;
		cout <<(f ?"Yes":"No");


	
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
struct edge{int to,cost;};
vector<int> G[100005];
 
long long int n,m,i,j=1,t;
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1,};
 
std::vector<P> tree[100010];
long long int dp[100005];
bool flag=false,toke;
bool used[100005];
char s[20];

ll ans=0;
long long int x,y,a,b;




int main(){
	cin>>x>>y;
	if(abs(x-y)<=1){
		cout<<"Brown";
	}else{
		cout<<"Alice";
	}
	cout<<endl;
	return 0;
}

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

#define mp make_pair
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<double,double>pdd;
double eps = 1e-9;
const int N = 1e5;
pdd arr[N+100];
int f[N+100];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lf%lf",&arr[i].first,&arr[i].second);
		char ch;
		getchar();
		scanf("%c",&ch);
		if(ch=='R'){
			f[i] = 1;
		}
		else if(ch=='D'){
			f[i] = 2;
		}
		else if(ch=='L'){
			f[i] = 3;
		}
		else f[i] = 4;
	}
	double lo = 0,hi = 1e12,ans=1e18;
	for(int j=1;j<=200;j++){
		double m1 = lo+(hi-lo)/3;
		double m2 = hi-(hi-lo)/3;
		double minx1 = 1e15,minx2 = 1e15,maxx1 = -1e15,maxx2 = -1e15;
		double miny1 = 1e15,miny2 = 1e15,maxy1 = -1e15,maxy2 = -1e15;
		for(int i=1;i<=n;i++){
			double t1,t2;
			if(f[i]==1){
				t1 = arr[i].first+m1;
				t2 = arr[i].second;
			}
			else if(f[i]==2){
				t1 = arr[i].first;
				t2 = arr[i].second-m1;
			}
			else if(f[i]==3){
				t1 = arr[i].first-m1;
				t2 = arr[i].second;
			}
			else{
				t1 = arr[i].first;
				t2 = arr[i].second+m1;
			}
			minx1 = min(minx1,t1);
			miny1 = min(miny1,t2);
			maxx1 = max(maxx1,t1);
			maxy1 = max(maxy1,t2);
		}
		for(int i=1;i<=n;i++){
			double t1,t2;
			if(f[i]==1){
				t1 = arr[i].first+m2;
				t2 = arr[i].second;
			}
			else if(f[i]==2){
				t1 = arr[i].first;
				t2 = arr[i].second-m2;
			}
			else if(f[i]==3){
				t1 = arr[i].first-m2;
				t2 = arr[i].second;
			}
			else{
				t1 = arr[i].first;
				t2 = arr[i].second+m2;
			}
			minx2 = min(minx2,t1);
			miny2 = min(miny2,t2);
			maxx2 = max(maxx2,t1);
			maxy2 = max(maxy2,t2);
		}
		double t1 = (maxx1-minx1)*(maxy1-miny1);
		double t2 = (maxx2-minx2)*(maxy2-miny2);
		ans = min(ans,t1);
		ans = min(ans,t2);
		if(t1-t2<eps){
			hi = m2;
		}
		else{
			lo = m1;
		}
	}
	printf("%.12lf\n",ans);
}


Measured memory_bytes: 2176
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {

   int H, W;
   cin >> H >> W;
   char s[H+1][W+1];
  
   int dh[] = {-1, 1, 0, 0};
   int dw[] = {0, 0, -1, 1};
   
   for (int h = 1; h <= H; h++) {
      for (int w = 1; w <= W; w++) {
         cin >> s[h][w];
      }
   }
   
   for (int h = 1; h < H; h++) {
      for (int w = 1; w < W; w++) {
         if (s[h][w] == '#') {
            bool flg = false;
            for (int i = 0; i < 4; i++) {
               int htmp = h+dh[i];
               int wtmp = w+dw[i];
               if (1 <= htmp && htmp <= H && 1 <= wtmp && wtmp <= W && s[htmp][wtmp] == '#') flg = true;
            }
            if (!flg) {
               cout << "No" << endl;
               return 0;
            }
         }
      }
   }

   cout << "Yes" << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;
static const int MAX = 200000;

int main(){
  int n,array[MAX];

  cin >> n;
  for(int i = 0; i < n ; i++) cin >> array[i];

  int minValue = array[0];
  int maxValue = array[1] - array[0];

  for(int i = 1; i < n ;i ++){
    maxValue = max(array[i] - minValue, maxValue);
    minValue = min(minValue,array[i]);
  }

  cout << maxValue << endl;

  return 0;
}



Measured memory_bytes: 3876
N = gets.to_i
r = N

def calc(r, i)
  if r < 6
    return [r, i]
  end

  j = 0
  v = 1
  while r >= v
    j += 1
    v = 6 ** j
  end

  result = []
  result << calc(r - 6 ** (j - 1), i + 1)

  if r >= 9
    j = 0
    v = 1
    while r >= v
      j += 1
      v = 9 ** j
    end

    result << calc(r - 9 ** (j - 1), i + 1)
  end

  result
end

d = calc(r, 0).flatten
result = []
0.step(d.size - 1, 2) do |i|
  result << d[i + 1] + d[i]
end
p result.min

Measured memory_bytes: 133428
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=1e5+2;
const LL INF=1e12;
PLL dp[MAX_N];
int main(){
    int N;cin>>N;
    vector<double>a(N);
    REP(i,N)cin>>a[i];
    double sum=0;
    REP(i,N){
        sum+=1.0/a[i];
    }
    cout<<fixed<<setprecision(10)<<1.0/sum<<endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    n=int(input())
    if n==0:
        break
    
    con=[0]*10

    for i in range(n):
        con[int(input())]+=1
    
    for i in range(10):
        if con[i]==0:
            print("-")
        else :
            for j in range(con[i]-1):
                print("*",end="")
            print("*")


Measured memory_bytes: 7584
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> g[100005];
int dist1[100005];
int dist2[100005];
void dfs1(int v,int p)
{
	for(int i=0;i<g[v].size();i++)
	{
		if(g[v][i]!=p)
		{
			dist1[g[v][i]]=dist1[v]+1;
			dfs1(g[v][i],v);
		}
	}
}
void dfs2(int v,int p)
{
	for(int i=0;i<g[v].size();i++)
	{
		if(g[v][i]!=p)
		{
			dist2[g[v][i]]=dist2[v]+1;
			dfs2(g[v][i],v);
		}
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs1(1,1);
	dfs2(n,n);
	int cnt1=0,cnt2=0;
	for(int i=1;i<=n;i++)
	{
		//cout<<dist1[i]<<" "<<dist2[i]<<endl;
		if(dist1[i]<=dist2[i])
		{
			cnt1++;
		}
		else
		{
			cnt2++;
		}
	}
	if(cnt1>cnt2)
	{
		cout<<"Fennec";
	}
	else
	{
		cout<<"Snuke";
	}
	return 0;
}

Measured memory_bytes: 12800
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2];
int i,j,k,l,t,n,m,tot;
void add(int x,int y){
    go[++tot]=y;
    nxt[tot]=h[x];
    h[x]=tot;
}
int perfect(int x,int y){
    int t=h[x];
    int p=0;
    while (t){
        if (go[t]!=y) p+=perfect(go[t],x);
        t=nxt[t];
    }
    if (p>=2) return p;
    else return p^1;
}
int main(){
    scanf("%d",&n);
    fo(i,1,n-1){
        scanf("%d%d",&j,&k);
        add(j,k);add(k,j);
    }
    if (perfect(1,0)==0) printf("Second\n");
    else printf("First\n");
}

Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
using namespace std;
const int mod = 1e9 + 7;
int a[200005];
long long sum[200005];
int main()
{
    int n;
    scanf("%d", &n);

    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    sum[0] = a[n];
    //cout << sum[0] << endl;
    for (int i = 1; i < n; i++)
    {

        sum[i] = (sum[i - 1] + a[n - i])%mod;
        //cout << sum[i] << endl;
    }
    long long ans = 0;
    for (int i = 1; i < n ; i++)
    {
        ans = ans + (a[i] * sum[n - i - 1] % mod);
        //cout << a[i] <<" "<< sum[n-i-1] << endl;
        ans %= mod;
    }
    printf("%lld\n", ans%mod);
}

Measured memory_bytes: 6172
N = int(input())
A = [0]*N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            a = x**2+y**2+z**2+x*y+z*x+y*z
            if a <= N:
                A[a-1]+= 1
for a in A:
    print(a)


Measured memory_bytes: 69344
using System;
using System.Collections.Generic;
					
public class my
{
	public static void Main()
	{
		string s;
		
		while( "0 0" != ( s = Console.ReadLine()) ) {
			var n = my.GetIntArray(2, s);
			
			if(n[0] == 0 && n[1] == 0)	break;
			
			switch( (my.GetDays(n[0]) + n[1]) % 7 ) {
				case 0:	Console.WriteLine("Wednesday");	break;
				case 1:	Console.WriteLine("Thursday");	break;
				case 2:	Console.WriteLine("Friday");	break;
				case 3:	Console.WriteLine("Saturday");	break;
				case 4:	Console.WriteLine("Sunday");	break;
				case 5:	Console.WriteLine("Monday");	break;
				case 6:	Console.WriteLine("Tuesday");	break;
			}
		}

	}
	
	private static int GetDays(int month)
	{
		return new int[] {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}[month - 1];
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}

	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static int[] GetIntArray(int n, string t)
	{
		var A = new int[n];
		var s = t.Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}

	private static int[] GetIntArray(char c)
	{
		return Array.ConvertAll(Console.ReadLine().Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(char c, string s)
	{
		return Array.ConvertAll(s.Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(string s)
	{
		return Array.ConvertAll(s.Split(' '), int.Parse);
	}
	
	private static double[] GetDoubleArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
	}
	
	public static string Reverse(string s)
	{
		var c = s.ToCharArray();
		Array.Reverse(c);
		
		return new String(c);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}

	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteVector(Vector v)
	{
		Console.WriteLine(string.Format("{0:f8} {1:f8}", v.X, v.Y));
	}
}

public struct Vector
{
	public double X,Y;
}

Measured memory_bytes: 8852
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))

visited_city = {1: 0}
visited_city_inv = {0: 1}

now = 1
num = 0
while True:
    next_city = arr[now - 1]
    num += 1
    if next_city not in visited_city:
        visited_city[next_city] = num
        visited_city_inv[num] = next_city
        now = next_city
    else:
        break

if k < num:
    ans = visited_city_inv[k]
else:
    x = visited_city[next_city]
    period = num - x
    ans = visited_city_inv[x + (k - x) % period]

print(ans)
# print(visited_city)


Measured memory_bytes: 49760
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// override by `ldflags`
var env = "online"

func checkLocal() bool {
	return env == "local"
}

func debugPrint(format string, args ...interface{}) {
	// debug out to stderr
	if checkLocal() {
		fmt.Fprintf(os.Stderr, format, args...)
	}
}

var (
	BufferSize = 100 + 10
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	} 
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	a := scanInt(sc)
	b := scanInt(sc)
	fmt.Println(a*b, 2*(a+b))
}


Measured memory_bytes: 1048
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c-'0'); 
	} 
	while((uint)((c=getchar())-'0')<10);
    return x;
}
 
const int dx[4]={0, 0, 1, -1};
const int dy[4]={1, -1, 0, 0};
 
int n, m, stx, sty, step[805][805], mx, res=2e9;
char grid[805][805];
queue<int> q;
 
inline bool out(int x, int y)
{
	return x<0||x==n||y<0||y==m;
}
 
void Init()
{
	n=in(), m=in(), mx=in();
	memset(step, -1, sizeof(step));
	forn(i, n)
		forn(j, m)
		{
			grid[i][j]=getchar();
			while(grid[i][j]!='.'&&grid[i][j]!='#'&&grid[i][j]!='S')
				grid[i][j]=getchar();
			if(grid[i][j]=='S')
				stx=i, sty=j;
		}
		
	q.push(stx), q.push(sty);
	
	step[stx][sty]=0;
	while(!q.empty())
	{
		int x=q.front();	q.pop();
		int y=q.front();	q.pop();
		if(step[x][y]==mx+1)
			break;
		for(int i=0; i<4; i++)
		{
			int xx=x+dx[i], yy=y+dy[i];
			if(!out(xx, yy)&&step[xx][yy]==-1&&grid[xx][yy]!='#')
			{
				step[xx][yy]=step[x][y]+1;
				q.push(xx);
				q.push(yy);
			}
		}
	}
	while(!q.empty())
		q.pop();
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			if(step[i][j]<=mx&&step[i][j]!=-1)
				q.push(i), q.push(j);
}
 
int main() 
{
	Init();
	while(!q.empty())
	{
		int x=q.front();	q.pop();
		int y=q.front();	q.pop();
		res=min(res, (min(min(n-x-1, x), min(y, m-y-1))+mx-1)/mx);
	}
	printf("%d", res+1);
	return 0;
}

Measured memory_bytes: 8576
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=b[a[0]-1]
for i in range(1,n):
  if a[i]==a[i-1]+1:
    s+=b[a[i]-1]+c[a[i-1]-1]
  else:
    s+=b[a[i]-1]
print(s)


Measured memory_bytes: 3064
from collections import deque
n, q =map(int, input().split())

c=[0]*n

G = [[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

for i in range(q):
    p, x=map(int, input().split())
    c[p-1] += x

ans = [0]*n

stack = deque()
stack.append([0, -1, 0])
while stack:
    v, parent, point = stack.pop()
    point += c[v]
    ans[v] = point
    for child in G[v]:
        if child == parent:
            continue
        stack.append([child, v, point])

print(*ans)

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<double, int> d_i;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];
	sort(a.begin(), a.end());
	int ma = -1, i0;
	rep(i, N) {
		int d = min(a[i], a[N - 1] - a[i]);
		if (d > ma) ma = d, i0 = i;
	}
	cout << a[N - 1] << ' ' << a[i0] << endl;
}


Measured memory_bytes: 640