akhauriyash/Code-Regression huggingface dataset:
use std::cmp::*;
use std::io::*;
const MOD: usize = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let t: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    if t[0] > a[0] || a[n - 1] > t[n - 1] {
        println!("0");
        return;
    }
    let mut kaku = vec![false; n];
    kaku[0] = true;
    kaku[n - 1] = true;
    for i in 1..n - 1 {
        if t[i - 1] < t[i] {
            if t[i] > a[i] {
                println!("0");
                return;
            }
            kaku[i] = true;
        }
    }
    for i in (1..n - 1).rev() {
        if a[i] > a[i + 1] {
            if t[i] < a[i] {
                println!("0");
                return;
            }
            kaku[i] = true;
        }
    }

    let mut ans = 1;
    for i in 1..n - 1 {
        if !kaku[i] {
            ans = ans * min(a[i], t[i]) % MOD;
        }
    }
    println!("{}", ans);
}


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

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll N;
vp_ll A,B;
int main(){
  TEST=true;
  cin >> N;
  A.assign(N+10,make_pair(0,0));
  for (ll i=1;i<=N;i++){
    cin >> A[i].first >> A[i].second;
  }
  ll idx=0;
  for (ll i=1;i<=N;i++){
    for (ll j=1;j<i;j++){
      ll x=A[i].first-A[j].first;
      ll y=A[i].second-A[j].second;
      if (x<0){
        x=-x;y=-y;
      }
      if (x==0 && y<0){
        x=-x;y=-y;
      }
      B.push_back(make_pair(x,y));
      idx++;
    }
  }
  ll ans_max=0;
  ll ans=0;
  if (N==1){
    cout << 1 << endl;
    return 0;
  }
  sort(B.begin(),B.end());
  for (ll i=1;i<idx;i++){
    if (B[i]==B[i-1]) ans++;
    else{
      if (ans>ans_max) ans_max=ans;
      ans=0;
    }
  }
  if (ans>ans_max) ans_max=ans;
  //cout << ans_max << endl;
  cout << N-ans_max-1 << endl;
  //show(B);
}


Measured memory_bytes: 256
#include "iostream"
#include "string"
using namespace std;
int main(void)
{
	int n,q;
	while (cin>>n>>q,n) {
		pair<string,pair<int,int> > p[n];
		for (int i = 0; i < n; i++) {
			cin>>p[i].first>>p[i].second.first>>p[i].second.second;
		}
		int query;
		for (int i = 0; i < q; i++) {
			bool f=false;
			cin>>query;
			for (int j = 0; j < n; j++) {
				if(p[j].second.second-p[j].second.first+1<=query&&query<=p[j].second.second)
				{
					cout<<p[j].first<<" "<<p[j].second.first-(p[j].second.second-query)<<endl;
					f=true;
				}
			}
			if(!f) cout<<"Unknown"<<endl;
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	set<int> a;
	rep(i, n)
	{
		int t;
		cin >> t;
		a.emplace(t);
	}

	cout << a.size() << endl;
	return (0);
}


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

using namespace std;

typedef long long int ll;

const ll MAXN = 1e5 + 5;

vector < vector < ll > > adj(MAXN, vector < ll >());
vector < bool > used;
vector < ll > d;

void bfs(ll u){
  queue < ll > q;
  q.push(u);
  used[u] = true;
  while(!q.empty()){
    ll v = q.front(); q.pop();
    for(auto to : adj[v]){
      if(!used[to]){
        d[to] = d[v] + 1;
        used[to] = true;
        q.push(to);
      }
    }
  }
}

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

  ll n, x, y;
  cin >> n >> x >> y;
  for(int i = 1; i < n; i++){
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);

  vector < ll > cnt(n + 1, 0);
  for(int i = 1; i <= n; i++){
    used.assign(n + 1, false);
    d.assign(n + 1, LLONG_MAX);
    d[i] = 0;
    bfs(i);
    for(int j = i + 1; j <= n; j++){
      cnt[d[j]]++;
    }
  }

  for(int i = 1; i < n; i++) cout << cnt[i] << endl;
}


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

int main() {
	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC" << endl;
	}
	else if (R < 2800) {
		cout << "ARC" << endl;
	}
	else if (R <= 4208) {
		cout << "AGC" << endl;
	}
		}

Measured memory_bytes: 256
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
	let N = parseInt(input[0][0], 10);
	let M = parseInt(input[0][1], 10);
	let A = input[1].map(e => parseInt(e, 10));
	let v = [-1,2,5,5,4,5,6,3,7,6];
	let priority = [[1],[7],[4],[5,3,2],[9,6],[8]];	
	let forUse = [];
	for (let x of priority){
		for (let y of x){
			if(A.indexOf(y) !== -1){
				forUse.push([y, v[y]]);
				break;
			}
		}	
	}
	// console.log(forUse);
	eachCount = Array.from({length: forUse.length}, () => 0);
	maxLength = 0;
	candidate = [];
	endPoint = 0;
	recurrent(forUse, 0, N);
	let ans = 0;
	let ary2 = [[0, 0]];
	for (x of candidate){
		let ary = [];
		for (let i = 0; i < x.length; i++){
			if (x[i] === 0) continue;
			ary.push([forUse[i][0], x[i]]);
		}
		ary.sort((a, b) => b[0] - a[0]);
		let flag;
		for (let i = 0; i < ary.length; i++){
			if (ary[0][0] === ary2[0][0] && ary[0][1] === ary2[0][1]) continue;
			if (ary[0][0] > ary2[0][0]) {
				flag = true;
				break;
			}
			if (ary[0][0] < ary2[0][0]) {
				flag = false;
				break;
			}
			if (ary[0][1] > ary2[0][1]) {
				flag = true;
				break;
			}
			if (ary[0][1] < ary2[0][1]) {
				flag = false;
				break;
			}
		}
		if (flag){
			ary2 = [];
			for (let x of ary){
				ary2.push(x.slice());
			}
		}

		// console.log(ary2);
	}
	let v_ans = [];
	for (let x of ary2){
		for (let i = 0; i < x[1]; i++){
			v_ans.push(x[0]);
		}
	}
	console.log(v_ans.join(""));


}

function recurrent(forUse, startPoint, remain){
	// console.log("start", startPoint, remain, eachCount);
	eachCount[startPoint] = Math.floor(remain / forUse[startPoint][1]);
	remain %= forUse[startPoint][1];
	// console.log("er", eachCount, remain);
	if (remain === 0) {
		let tmp = 0;
		for(let i = 0; i <= startPoint; i++){
			tmp += eachCount[i];
		}
		if (tmp > maxLength){
			maxLength = tmp;
			let v2 = eachCount.slice();
			v2.length = startPoint + 1;
			candidate = [v2];
		} else if (tmp === maxLength){
			let v2 = eachCount.slice();
			v2.length = startPoint + 1;
			candidate.push(v2);
		}
		// console.log("OK→", eachCount); 
		eachCount[startPoint] = 0;
		
		return;
	} else {
		for (let i = eachCount[startPoint]; i >= 0; i--){
			if ((startPoint + 1) > (forUse.length - 1)) return;
			recurrent(forUse, startPoint + 1, remain);
			remain += forUse[startPoint][1];
			eachCount[startPoint] --;
			if (startPoint === 0 && eachCount[0] + (remain / forUse[1][1] )< maxLength) return;
		}
	}
	eachCount[startPoint] = 0;

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
	int a , b ;
	cin >> a >> b ;

	int c =  a * b  ;
	
	if(c % 2 == 0){
	cout << "Even" << endl ;
	}
	else
	{
	cout << "Odd" << endl;
	}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll X, Y;
    cin >> X >> Y;

    ll ans = 0;

    rep (i, X + 1)
    {
        const ll x = i;
        const ll y = X - i;

        const ll xx = x * 2;
        const ll yy = y * 4;

        if (xx + yy == Y) { ++ans; }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
            #define ll long long
            #define f   first
            #define s   second
            #define pb          push_back
            #define mod        1000000007
            #define mod1       1000000009
            #define hell        998244353
            #define inf         1000000000000000000LL
            #define pi          3.14159265358979323
            //#define N           100005 
            const int N=1000005;
            using namespace std;
            ll n,k,sum,q,res,m,val,ans;
            ll x,y;
            double p;
            ll xx[]={1,0,-1,0};
            ll yy[]={0,1,0,-1};
            ll spf[N];
            void f()
            {
                for(int i=1;i<N;i++) spf[i]=i;
                for(int i=4;i<N;i+=2) spf[i]=2;
                for(int i=3;i*i<N;i+=2)
                {       if(spf[i]==i){
                        for(int j=i*i;j<N;j+=i)
                        {
                            if(spf[j]==j) spf[j]=i;
                        }
                        }     
                }
            }
            void solve()    
            {   ll a,b,c;
                cin>>n;
                map<ll,ll> hm;
                vector<ll> v(n);
                for(int i=0;i<n;i++) cin>>v[i];
                for(int i=0;i<n;i++)
                {
                    x=v[i];
                    while(x>1)
                    {
                        ll y=spf[x];
                        hm[y]++;
                        while(x%y==0) {x/=y;}
                    }
                }
                ll res=v[0];
                for(int i=1;i<n;i++) res=__gcd(res,v[i]);
                bool f=0;
                for(auto x:hm)
                {
                    if(x.s>1) f=1;
                }
                if(!f) cout<<"pairwise coprime";
                else if(res==1) cout<<"setwise coprime";
                else cout<<"not coprime";
                
                
            }
            int main()  
            {   ios_base::sync_with_stdio(false);
                cin.tie(0);cout.tie(0);
                ll t=1;
                f();
                //cin>>t;
                 for(ll i=1;i<=t;i++)
                    solve();
                
            }            


Measured memory_bytes: 23788
def resolve():
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))
    ans = 0
    for _ in range(N):
        A = list(map(int, input().split()))
        score = 0
        for i in range(M):
            score += A[i] * B[i]
        if score + C > 0:
            ans += 1
    print(ans)
    return
  
resolve()

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
#define fs first
#define sc second
typedef pair<int, int> P;

vector<P> G[100000];
int d[100000];

void dfs(int n, int par, int c){
    int ind = 1;
    for(int i = 0; i < (int)G[n].size(); i++){
        int nx = G[n][i].fs;
        if(nx == par) continue;

        if(ind == c) ind++;
        G[n][i].sc = ind;
        dfs(nx, n, ind);
        ind++;
    }

    return;
}

int main(){
    int N;
    cin >> N;
    P p[N - 1];
    for(int i = 0; i < N - 1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        p[i].fs = a;
        p[i].sc = G[a].size();
        d[a]++;
        d[b]++;
        G[a].push_back(P(b, -1));
        G[b].push_back(P(a, -1));
    }

    int mx = 0;
    for(int i = 0; i < N; i++){
        mx = max(mx, d[i]);
    }

    cout << mx << endl;
    dfs(0, -1, -1);

    for(int i = 0; i < N - 1; i++){
        cout << G[p[i].fs][p[i].sc].sc << endl;
    }

    return 0;
}


Measured memory_bytes: 9728
H,W = map(int,input().split())
A = []*H
for i in range(H):
    A.append(list(map(int,input().split())))

for h in range(H):
    for w in range(W):
        A[h][w] %= 2


Ans = []
for h in range(H):
    if h%2==0:
        for w in range(W-1):
            if A[h][w]==1:
                Ans.append([h+1,w+1,h+1,w+2])
                A[h][w+1] += 1
        if A[h][W-1]==1 and h+1!=H:
            Ans.append([h+1,W,h+2,W])
            A[h+1][W-1] += 1
    else:
        for w in range(W-1):
            wt = W-1-w
            if A[h][wt]==1:
                Ans.append([h+1,wt+1,h+1,wt])
                A[h][wt-1] += 1
        if A[h][0]==1 and h+1!=H:
            Ans.append([h+1,1,h+2,1])
            A[h+1][0] += 1

print(len(Ans))
for ans in Ans:
    print(" ".join(map(str,ans)))


Measured memory_bytes: 29868
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 1(mod 3)のグループと2(mod 3)を先に決める
N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

root = 1
rank = [0] * (N+1) # 1-indexed
rank[1] = 1
parent = [0] * (N+1) # 1-indexed
stack = [root]
while stack:
    cur = stack.pop()
    r = rank[cur]
    for next in graph[cur]:
        if next == parent[cur]:
            continue
        parent[next] = cur
        rank[next] = r + 1
        stack.append(next)

counter = [0, 0]
for x in rank[1:]:
    counter[x%2] += 1
num0mod3 = N // 2
num1mod3 = (N+2) // 3
num2mod3 = (N+1) // 3
answer = [0] * (N+1)
if max(counter) >= num1mod3 + num2mod3:
    #この時ここに1mod3、2mod3を全部入れる
    if counter[0] > counter[1]:
        index = 0
    else:
        index = 1
    cur = 1
    used = set()
    for i in range(1, N+1):
        if rank[i] % 2 == index:
            answer[i] = cur
            used.add(cur)
            cur += 1
            if cur % 3 == 0:
                cur += 1
            if cur > N:
                break
    cur = 1
    for j in range(1, N+1):
        while cur in used:
            cur += 1
        if answer[j] == 0:
            answer[j] = cur
            used.add(cur)
else:
    #ここではcounterの多い方にnum1mod3を入れる
    if counter[0] > counter[1]:
        index = 0
    else:
        index = 1
    cur = 1
    used = set()
    for i in range(1, N+1):
        if rank[i] % 2 == index:
            answer[i] = cur
            used.add(cur)
            cur += 3
            if cur > N:
                break
    cur = 2
    for i in range(1, N+1):
        if rank[i] % 2 == 1-index:
            answer[i] = cur
            used.add(cur)
            cur += 3
            if cur > N:
                break
    cur = 1
    for j in range(1, N+1):
        while cur in used:
            cur += 1
        if answer[j] == 0:
            answer[j] = cur
            used.add(cur)

print(*answer[1:])


Measured memory_bytes: 113100
H,W,A,B = map(int,input().split())
for j in range(H):
    if j < B:
        for i in range(W):
            if i < A:
                print(0,end="")
            else:
                print(1,end="")
        print()
    else:
        for i in range(W):
            if i < A:
                print(1,end="")
            else:
                print(0,end="")
        print()

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

using namespace std;

int const N = 1234567;
long long dp[N], dp1[N];
long long x[N];
long long const INF = 1LL << 60;
int const T = 1 << 20;

long long f[T + T + 5];

void setit(int x, long long y) {
  x += T;
  f[x] = y;
  while (x > 1) {
    x >>= 1;
    f[x] = std::min(f[x + x], f[x + x + 1]);
  }
}

long long getmin(int l, int r) {
  l += T;
  r += T;
  long long ret = INF;
  while (l <= r) {
    if (l & 1) ret = std::min(ret, f[l++]);
    if (~r & 1) ret = std::min(ret, f[r--]);
    l >>= 1;
    r >>= 1;
  }
  return ret;
}

int main() {
  int n, ex, T;
  scanf("%d%d%d", &n, &ex, &T);
  for (int i = 1; i <= n; i++) {
    int y;
    scanf("%d", &y);
    x[i] = y;
  }
  for (int i = 0; i <= n; i++) {
    dp[i] = INF;
  }
  dp[0] = 0;
  x[0] = 0;
  // for (int i = 0; i < n; i++) {
  //   for (int j = i + 1; j <= n; j++) {
  //     long long first = dp[i] + x[i + 1] - x[i] + T;
  //     long long last = dp[i] + x[j] - x[i];
  //     long long back = last + x[j] - x[i + 1];
  //     back = std::max(back, first);
  //     last = back + x[j] - x[i + 1];
  //     dp[j] = std::min(dp[j], last);
  //   }
  // }
  dp1[0] = 0 - x[0] - 2 * x[1];
  for (int i = 0; i <= n; i++) setit(i, INF);
  setit(0, 0);
  for (int i = 1, w = 0; i <= n; i++) {
    while (w < i && 2 * (x[i] - x[w + 1]) > T) ++w;
    if (w > 0) {
      // printf("%d %lld\n", i, 3LL * x[i] + dp1[w - 1]);
      dp[i] = std::min(dp[i], 3LL * x[i] + dp1[w - 1]);
    }
    dp[i] = std::min(dp[i], x[i] + T + getmin(w, i - 1));
    dp1[i] = std::min(dp[i] - x[i] - 2 * x[i + 1], dp1[i - 1]);
    setit(i, dp[i] - x[i]);
    // printf("%lld\n", dp[i]);
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = i + 1; j <= n; j++) {
  //     dp[j] = std::min(dp[j], std::max<long long>(2 * (x[j] - x[i + 1]), T) + x[j] - x[i] + dp[i]);
  //   }
  //   printf("%lld\n", dp[i + 1]);
  // }
  // for (int i = 0; i < n; i++) {
  //   long long end = (long long) i * T + x[n - 1];
  //   long long next = std::max(end + x[n - 1] - x[i], x[i] + (long long) (i + 1) * T);
  //   ans = std::min(ans, next + ex - x[i]);
  // }
  printf("%lld\n", ex - x[n] + dp[n]);
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,m,X,Y,flg = 0,mn=1000,mx=0;
    cin >> n >> m >> X >> Y;
    vector<int> x(n),y(m);
    for(int i = 0;i < n;i++){
        cin >> x[i];
    }
    for(int i = 0;i < m;i++) cin >> y[i];
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(x[i] >= y[j] || x[i] >= Y || y[j] <= X){
                flg = 1;
                break;
            }
        }
    }
    
    for(int i = 0;i < m;i++){
        mn = min(Y,y[i]);
    }
     for(int i = 0;i < n;i++){
        mx = max(X,x[i]);
    }
    
    if(mn <= mx) flg = 1;
    
    if(flg == 1){
        cout << "War"<< endl;
    }else{
        cout << "No War"<< endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b, c, d, n;

signed main() {
	cin >> a >> b >> c >> d >> n;
	if (n % 2)cout << min({ d*(n / 2),c*(n-1),b * 2 * (n-1),a * 4 * (n-1) }) + min({ a * 4,b * 2,c }) << endl;
	else cout << min({ d*(n / 2),c*n,b * 2 * n,a * 4 * n }) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {
  int n;
  scanf("%d", &n);
  int k;
  scanf("%d", &k);
  vector<int> h(n);
  for (int& x : h) {
    scanf("%d", &x);
  }
  vector<int> dp(n, INF);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j <= i + k; ++j) {
      if (j < n) {
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
      }
    }
  }
  printf("%d\n", dp[n - 1]);
}

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

int main() {
  int a,b,c,d,r,l;
  cin >> a >> b >> c >> d;
  l = a+b;
  r = c+d;
  if ( r > l ){
    cout << "Right" << endl;
  }
  else if ( r == l ){
  cout << "Balanced" << endl;
  }
  else {
    cout << "Left" << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			long n = sc.nextInt();
			if(n == 0) break;
			
			int r = 1;
			for(long i=2;i*i<=n;i++) if(n%i==0){
				r += i + n/i;
				if(i*i==n) r -= i;
			}
			if(n == 1) r--;
			if(r == n) System.out.println("perfect number");
			if(r < n) System.out.println("deficient number");
			if(r > n) System.out.println("abundant number");
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 19884
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll n,in;
	cin >> n;
	vector<ll> a(n);
	REP(i,n){
		cin >> in;
		a[i] = in - (i+1);
	}
	
	sort(a.begin(),a.end());
	ll b1;
	if(n%2) b1 = a[n/2];
	else b1 = (a[n/2-1]+a[n/2])/2;
	
	ll ans1=0;
	REP(i,n){
		ans1 += abs(a[i]-b1);
	}
	
	cout << ans1 << endl;
	
	return 0;
}

Measured memory_bytes: 4820
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n, t;
    scanf("%d %d", &n, &t);
    vector<int> nn(n);
    for(int i = 0; i < nn.size(); i++) {
        scanf("%d", &nn[i]);
    }
    int sum = 0;
    for(int i = 1; i < nn.size(); i++) {
        int now = nn[i] - nn[i - 1];
        sum += now > t? t: now;
    }
    sum += t;
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
  int i,len,flg;
  char s[84];

  while(fgets(s,84,stdin) != NULL){
    len = strlen(s) - 1;
    flg = 1;

    while(flg){
      for(i=0;i<len;i++)
	if(islower(s[i]))
	  s[i] = (s[i] - 'a' + 1) % 26 + 'a';

      for(i=0;i<len;i++){
	if(!strncmp(&s[i],"the",3) || !strncmp(&s[i],"this",4) || !strncmp(&s[i],"that",4)){
	  flg = 0;
	  break;
	}
      }
    }
    printf("%s",s);
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r;
    cin >> r;
    cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
bool kansu( pair< string, long long int > p, pair< string, long long int > q ) {
 
  if ( p.first[1] < q.first[1] ) return true;
 
  return false;
 
}
 
void print( long long int n, vector< pair< string, long long int > > v ) {
 
  bool f = true;
 
  for ( long long int i = 0; i < n; i++ ) {
 
    if ( i != 0 ) {
      cout << " ";
      if ( v[i-1].first[1] == v[i].first[1] && v[i-1].second > v[i].second ) f = false;
    }
    cout << v[i].first;
 
  }
 
  cout << endl;
 
  if ( f == true ) {
    cout << "Stable" << endl;
  }else {
    cout << "Not stable" << endl;
  }
 
  return;
 
}
 
void BubbleSort( long long int n, vector< pair< string, long long int > > v ) {
 
  for ( long long int i = 0; i < n; i++ ) {
 
    for ( long long int j = n - 1; j > i; j-- ) {
 
      if ( kansu( v[j], v[j-1] ) == true ) swap( v[j], v[j-1] );
 
    }
 
  }
 
  print( n, v );
 
  return;
 
}
 
void SelectionSort( long long int n, vector< pair< string, long long int > > v ) {
 
  for ( long long int i = 0; i < n; i++ ) {
 
    long long int minj = i;
 
    for ( long long int j = i; j < n; j++ ) {
 
      if ( kansu( v[j], v[minj] ) == true ) minj = j;
 
    }
 
    swap( v[i], v[minj] );
 
  }
 
  print( n, v );
 
  return;
 
}
 
int main() {
 
  long long int n;
  cin >> n;
 
  vector< pair< string, long long int > > v;
 
  for ( long long int i = 0; i < n; i++ ) {
 
    string in;
    cin >> in;
 
    v.push_back( make_pair( in, i ) );
 
  }
 
  BubbleSort( n, v );
  SelectionSort( n, v );
 
  return 0;
 
}

Measured memory_bytes: 3164
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val Array(a,b) = new BufferedReader(new InputStreamReader(System.in)).readLine().split("\\s+").map(_.toInt)
    System.out.println(
      if (a < 10 && b < 10) {
        a * b
      } else {
        -1
      }
    )
  }
}


Measured memory_bytes: 27284
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	string s,r;
	int x[26] = {0};
	char a = 'a';
	do{
		getline(cin,r);
		s += r;
	}while(r != "");
	REP(i,s.length()){
		REP(j,26){
			if((int)(s[i] - 'a') == j || (int)(s[i] - 'A') == j){
				x[j]++;
			}
		}
	}
	REP(i,26){
		cout << (char)(a + i) << " : " << x[i] << endl; 
	}
}

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

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

    if (s.size() < t.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for (int i = s.size() - t.size(); i >= 0; i--) {
        bool f = true;
        int k = 0;
        for (int j = i; j < i + t.size(); j++) {
            if (s[j] == t[k] || s[j] == '?') ;
            else f = false;
            k++;
        }
        if (f) {
            k = 0;
            for (int j = i; j < i + t.size(); j++) {
                if (s[j] == '?') s[j] = t[k];
                k++;
            }
            break;
        }
        if (i == 0) {
            cout << "UNRESTORABLE" << endl;
            return 0;
        }
    }

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '?') s[i] = 'a';
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int selectionSort(int *,int );
int main(){
  int count,kazu,A[100],i;
  scanf("%d",&kazu);
  for(i=0;i<kazu;i++){
    scanf("%d",&A[i]);
  }
  count=selectionSort(A,kazu);
  for(i=0;i<kazu;i++){
    if(i!=kazu-1){
      printf("%d ",A[i]);
    }
    else{printf("%d",A[i]);
    }
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

int selectionSort(int *A,int N){
  int minj,j,reset,count=0,i;
  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
	minj=j;
      }

    }
    if(A[i]!=A[minj]){count++;}
    reset=A[i];
    A[i]=A[minj];
    A[minj]=reset;
    
  }
  
  return count;
}

  
      
  



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll INF=1000000010;
const ll MOD=1000000007;
const ll LINF=4000000000000000000;
const long double EPS=1e-9;
typedef pair<int,int> P;
int c[1010][1010];
bool f[1010][1010];
int main(){
    int co=0;
    int q,n;cin>>q>>n;q--;
    for(int i=1;i<=n;i++){
        string s;cin>>s;
        for(int j=0;j<n;j++){
            if(s[j]=='1'){
                c[i][j+1]=1;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(!c[i][j]){
                if(c[n-i+1][j]){
                    co++;
                }
                if(c[i][n-j+1]){
                    co++;
                }
            }
        }
    }
    int ans=0;
    if(co==0)ans++;
    while(q--){
        int d;cin>>d;
        for(int i=0;i<d;i++){
            int y,x;cin>>y>>x;
            int ny=n-y+1,nx=n-x+1;
            if(c[y][x]){
                c[y][x]=0;
                if(c[ny][x]){
                    co++;
                }else{
                    co--;
                }
                if(c[y][nx]){
                    co++;
                }else{
                    co--;
                }
            }else{
                c[y][x]=1;
                if(c[ny][x]){
                    co--;
                }else{
                    co++;
                }
                if(c[y][nx]){
                    co--;
                }else{
                    co++;
                }
            }
        }
        if(co==0)ans++;
    }
    cout<<ans<<endl;
}   



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

int main() {
    ll x,y;
    cin >> x >> y;
    ll ans;
    if (x * y > 0) {
        if (y >= x) ans = y - x;
        else ans = x - y + 2;
    } else if (x * y < 0) {
        ans = abs(abs(x)-abs(y)) + 1;
    } else {
        if (y > x) ans = y - x;
        else if (y == x) {
            ans = 0;
        } else {
            ans = x - y + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <utility>
#include <bitset>
#include <cstdio>

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

using namespace std;

int main () {
    int a, b, x;
    cin >> a >> b >> x;
    double result = atan((b-(double)x/a/a) * 2 / a) / M_PI * 180;
    double limit = atan((double)x / a / a / a * 2) / M_PI * 180;
    if (result > limit) {
        result = atan((double)a * b * b / 2 / x) / M_PI * 180;
    }
    
    printf("%lf\n", result);

    return 0;
}

Measured memory_bytes: 256
mod = 10**9 + 7
n,k= [int(i) for i in input().split()]

d = [0] * (k + 1)

for i in range(1,k+1):
    d[i] = pow(k//i,n,mod)
    
    
for i in range(k,0,-1):
    for j in range(2*i,k+1,i):
        d[i] -= d[j]
        d[i] %= mod
        
ans = 0 
for idx,i in enumerate(d):
    ans += (idx) * i
    ans %= mod

print(ans)
        

Measured memory_bytes: 11032
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,k; cin>>n>>k;
    vector<bool>flag(11,true);
    rep(i,k){
        int hoge; cin>>hoge;
        flag[hoge]=false;
    }
    for(int i=n;;i++){
        string hoge=to_string(i);
        bool foo=true;
        rep(i,hoge.size()){
            if(!flag[hoge[i]-'0'])foo=false;
        }
        if(foo){cout<<i<<endl;
        return 0;
        }
    }
}

Measured memory_bytes: 256
import math
pi = math.pi
a, b, h, m = map(int, input().split())
theta1 = pi * h / 6 + pi * m / 360
theta2 = pi * m / 30
x1 = a * math.cos(theta1)
y1 = a * math.sin(theta1)
x2 = b * math.cos(theta2)
y2 = b * math.sin(theta2)
l = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(l)

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

using namespace std;

int main(){
	int height, width;
	cin >> height >> width;
	vector<string> pixcel(height);
	for(int i = 0; i < height; i++){
		cin >> pixcel[i];
	}

	for(int j = 0; j < width + 2; j ++){
		cout << '#';
	}
	cout << endl;

	for(int i = 0; i < height; i++){
		cout << '#' << pixcel[i] << '#' << endl;
	}

	for(int j = 0; j < width + 2; j ++){
		cout << '#';
	}
}


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

int main() {
	
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    while(h!=0 || w!=0){
        int i, j;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(i==0 || j==0 || i==h-1 || j==w-1){
                    cout << "#" ;
                }
                else cout << "." ;
                }
                cout << endl ;
            }
            cout << endl ;
            cin >> h >> w ;
        }
        return 0 ;
    }



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

int main() {
	int x, a, b;
	cin >> x >> a >> b;

	if (a >= b) cout << "delicious" << endl;
	else if (a < b && b - a <= x) cout << "safe" << endl;
	else cout << "dangerous" << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-(x)))
#define MP make_pair
#define fi first
#define se second
#ifdef __LOCAL_DEBUG__
# define _debug(fmt, ...) fprintf(stderr, "\033[94m%s: " fmt "\n\033[0m", \
    __func__, ##__VA_ARGS__)
#else
# define _debug(...) ((void) 0)
#endif
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 300 + 11;
const int MOD = 1e9 + 7;
int N, M, T;
LL dp[maxn][maxn][maxn];
int main(){
    cin >> N >> M;
    dp[0][1][1] = 1;
    for (int i = 0; i < M; i++){
        for (int j = 0; j <= min(i + 1, N); j++){
            for (int k = 0; k <= j; k++){
                dp[i+1][j+1][k] += dp[i][j][k]*(N-j);
                dp[i+1][j][k] += dp[i][j][k]*(j-k);
                dp[i+1][j][j] += dp[i][j][k]*k;
                dp[i+1][j+1][k] %= MOD;
                dp[i+1][j][k] %= MOD;
                dp[i+1][j][j] %= MOD;
            }
        }
    }
    cout << dp[M][N][N] % MOD << endl;
    return 0;
}


Measured memory_bytes: 227584
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
dgraph = [[] for _ in range(n)]
edges = [[] for _ in range(n)]
eds = set()
visited = [False for i in range(n)]

def spanning_tree(i):
  if visited[i]:
    return
  visited[i] = True
  for to in graph[i]:
    if not visited[to]:
      edges[i].append(to)
      eds.add((i, to))
      spanning_tree(to)

def const_dgraph(i):
  ce = 0
  for to in edges[i]:
    c = const_dgraph(to)
    if c == 0:
      dgraph[i].append(to)
    else:
      dgraph[to].append(i)
  return len(dgraph[i]) % 2

if m % 2 == 1:
  print(-1)
else:
  for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
  spanning_tree(0)
  for i, g in enumerate(graph):
    for to in g:
      if (i, to) not in eds and (to, i) not in eds:
        dgraph[i].append(to)
        eds.add((i, to))
  visited = [False for _ in range(n)]
  const_dgraph(0)
  if len(dgraph[0]) % 2 == 1:
    print(-1)
  else:
    for i, g in enumerate(dgraph):
      for to in g:
        print("%d %d" % (i+1, to+1))


Measured memory_bytes: 143272
#include <iostream>
using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, s[26] = { 0 }, t[26] = { 0 };
	string S, T;
	cin >> S >> T;

	for (i = 0; S[i]; i++) {
	
			s[S[i] - 'a']++;
			t[T[i] - 'a']++;
		
		
	}
	for (i = 0; i < 25; i++) {
		for (j = 25; j >= 1 + i; j--) {
			if (s[j] > s[j - 1]) {
				k = s[j];
				s[j] = s[j - 1];
				s[j - 1] = k;
			}
			if (t[j] > t[j - 1]) {
				k = t[j];
				t[j] = t[j - 1];
				t[j - 1] = k;
			}
		}
	}
	for (i = 0; i < 26; i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    cout << (n ^ 1) << endl;
    //printf("%.12f", ans);
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<long long, long long>> A;
    for (int i = 0; i < N; i++) {
        long long price, num;
        cin >> price >> num;
        A.emplace_back(price, num);
    }
    sort(A.begin(), A.end());
    long long ans = 0, buy = 0;
    for (int i = 0; i < N; i++) {
        if (buy + A[i].second <= M) {
            buy += A[i].second;
            ans += A[i].first * A[i].second;
        } else {
            long long K = M - buy;
            ans += A[i].first * K;
            buy += K;
        }
        if (buy == M) break;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    for(int i=1;i<n+1;i++){
        if(i%3==0||(i/10)%10==3||(i/100)%10==3||(i/1000)%10==3||i%10==3){
            cout<<" "<<i;
            
        }
      
    }
    cout<<endl;
}


Measured memory_bytes: 3076
// 2011/02/12 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int memo[31];
	memo[0] = 0;
	memo[1] = 1;
	memo[2] = 2;
	memo[3] = 4;
	for(int i=4; i<=30; i++)
		memo[i] = memo[i-1]+memo[i-2]+memo[i-3];

	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		cout << ((memo[n]+9)/10+364)/365 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = 1.000000 * a / b;
    // printf("%d %d %.8lf\n", d, r, f);
    cout << d << " " << r << " " << std::fixed << f << endl;
     return 0;
}







Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int id = 0;
    while (id < s.size()) {
        if (s[id] == 'e') {
            string tmp = s.substr(id,6);
            if (tmp == "eraser") id += 6;
            else {
                tmp = s.substr(id,5);
                if (tmp == "erase") id += 5;
                else {cout << "NO" << endl; return 0;}
            }
        }
        else if (s[id] == 'd') {
            string tmp = s.substr(id,7);
            if (tmp == "dreamer") {
                if (s[id+7] == 'a') id += 5;
                else id += 7;
            } else {
                tmp = s.substr(id,5);
                if (tmp == "dream") id += 5;
                else {cout << "NO" << endl; return 0;}
            }
        }
        else {cout << "NO" << endl; return 0;}
    }
    cout << "YES" << endl;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> a(n);
	rep(i, 0, n)a[i] = pair<int, int>(0, i + 1);
	rep(i, 0, m) {
		int e; cin >> e; e--;
		a[e].first = -(i + 1);
	}
	sort(a.begin(), a.end());
	rep(i, 0, a.size()) {
		cout << a[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for (int i=1; i<=(n); ++i)
#define drep(i,n) for (int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)
#define pu push_back
#define po pop_back
#define EPS (1e-7)
#define INF (1e9)
#define pi (acos(-1))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vec vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
//const int INF = 1001001001;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//gcd & lcm
ll gcd (ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}
ll lcm (ll a, ll b) {
  return a/gcd(a,b)*b;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //FROM HERE//
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int a,b;
  a = 60*h1+m1;
  b = 60*h2+m2;
  cout << b-a-k << endl;
  return 0;
}





Measured memory_bytes: 3688
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //日付を入力する
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);


            //hとwの大小を比較して、おおきい方で塗っていく。割り切れるときと割り切れないときで回数が違うので場合分け
            if(m == n)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            
        }
    }

Measured memory_bytes: 11092
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  var a = Array.fill(n)(sc.nextInt)

  var ans = false
  var checked = false
  // チェック済みのインデックスを保持（以降は同じところをまわる）
  val checkedIndex = scala.collection.mutable.Set[Int]()
  var i = 0
  var count = 0
  while (ans == false && checked == false) {
    count += 1
    if (a(i) == 2) {
      ans = true
    } else {
      val tmp = a(i) - 1
      if (checkedIndex.contains(tmp)) {
        checked = true
      } else {
        checkedIndex.add(tmp)
      }
      i = tmp
    }
  }

  println(if (ans) count else -1)

}


Measured memory_bytes: 54032
import sys
from collections import deque
from bisect import bisect_left

input = sys.stdin.readline

def f(n):
    r = deque()
    for _ in range(n):
        a = int(input())
        i = bisect_left(r, a)
        if i:
            r[i - 1] = a
        else:
            r.appendleft(a)
    print(len(r))

n = int(input())
f(n)


Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) (x).begin (),(x).end()
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define endl "\n"
#define si set<ll>
#define rep(i,a,b) for(unsigned ll i=a;i<b;i++)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MOD 1000000007LL
ll binary_power(ll a, ll n) {
    if (n==0) return 1;
    ll k=binary_power(a,n/2);
    if (n%2==0) return (k*k)%MOD;
    else return (((k*k)%MOD)*a)%MOD;
}

void solve()
{   int n,k;
    cin >> n >> k;
    vi dp(k+1);
    ll ans=0;
    for(ll i=k; i>=1; i--) {
        dp[i]=binary_power(k/i,n);
        ll j=i+i;
        while (j<=k) {
            dp[i]=(dp[i]+MOD-dp[j])%MOD;
            j+=i;
        }
        ans=(ans+(dp[i]*i)%MOD)%MOD;
    }
    cout << ans << endl;
}

int main()
{
    SPEED;
    ll t = 1;

   //cin>>t;

    while(t--) solve();

   return 0;
}


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

int main(){
	int n;
	while(cin>>n,n){
		int a[114];
		for(int i=0;i<n;i++)cin>>a[i];
		int k;
		cin>>k;
		
		int lb=-1;
		int ub=n;
		int ans=0;
		while(ub-lb>1){
			int mid=(ub+lb)/2;
			if(a[mid]==k){
				ans++;
				break;
				}
			else if(a[mid]>k){
				ans++;
				ub=mid;
				}	
			else{
				ans++;
				lb=mid;
				}	
			}
		cout<<ans<<endl;	
		}
		return 0;
	}

Measured memory_bytes: 3084
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);
        int men, syuu;
        men = a * b;
        syuu = 2 * a + 2 * b;
        Console.WriteLine(men + " " + syuu);
    }   
}

Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
typedef long long  ll;

using namespace std;

int ans, cnt;

int main() {

	int N,R;
	cin >> N >> R;
	if (N >= 10) ans = R;
	else {
		ans = R + 100 * (10 - N);
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256