akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
  var a, b, c, d int
  fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
  switch {
    case a-c<=d && a-c>=-d:
    	fallthrough
    case (a-b<=d && a-b>=-d) && (c-b<=d && c-b>=-d):
    	fmt.Println("Yes")
    default:
    	fmt.Println("No")
  }
}

Measured memory_bytes: 512
def main():
    # エラトステネスのふるい
    MAX_NUM = 101010
    is_prime = [1 for _ in range(MAX_NUM)]
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, MAX_NUM):
        if not is_prime[i]:
            continue
        for j in range(i * 2, MAX_NUM, i):
            is_prime[j] = 0

    # 2017-like 数かどうか
    like2017 = [0 for _ in range(MAX_NUM)]
    for i in range(MAX_NUM):
        if i % 2 == 0:
            continue
        if is_prime[i] and is_prime[(i + 1) // 2]:
            like2017[i] = 1

    # 累積和
    cumsum = [0 for _ in range(MAX_NUM + 1)]
    for i in range(MAX_NUM):
        cumsum[i + 1] = cumsum[i] + like2017[i]

    Q = int(input())
    L = [None] * Q
    R = [None] * Q
    for i in range(Q):
        l, r = map(int, input().split())
        L[i] = l
        R[i] = r

    for i in range(Q):
        print(cumsum[R[i] + 1] - cumsum[L[i]])


if __name__ == "__main__":
    main()


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


int main(void)
{
  long long n, m, count=0;
  cin >> n >> m;
  
  count = min(n, m/2);
  n -= count;
  m -= count*2;
  
  count += m/4;
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, n) for (int i = 1; i <= (n); i++)
#define pp(v) cout << #v << "=" << (v) << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  string s; cin >> s;
  int len = s.size();

  int ans = 1e9;
  rep(i,len-2) {
    int sum = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
    ans = min(ans, abs(sum - 753));
  }
  cout << ans << endl;
}


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


void solve(long long N, std::vector<long long> A){
  const long long M = 1'000'005;
  vector<long long> cnt(M, 0);
  for (long long a : A) {
    if (cnt[a] != 0) {
      cnt[a] = 2;
      continue;
    }
    for (long long i=a; i<M; i+=a) cnt[i]++;
  }

  long long ans = 0;
  for (auto a : A) {
    if (cnt[a] == 1) ans++;
  }
  cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 12792
from collections import deque

def bfs(idx,k,colored):
  q = deque()
  visited[idx] = True
  q.append(idx)
  while q:
    r = q.pop()
    color = 0
    for n in graph[r].keys():
      if not visited[n]:
        if color == colored[r]: color+=1
        colored[n] = color
        graph[r][n] = color
        graph[n][r] = color
        color += 1

        visited[n] = True
        q.append(n)

        
N = int(input())
graph = {}
colored = [-1]*(N+1)
visited = [False]*(N+1)
for i in range(N+1):
  graph[i] = {}
ab = []
for i in range(N-1):
  a,b = map(int,input().split())
  ab.append((a,b))
  graph[a][b] = -1
  graph[b][a] = -1
  
k = max([len(graph[i]) for i in range(1,N+1)])

bfs(1,k,colored)
print(k)
for a,b in ab:
  print(graph[a][b]+1)


Measured memory_bytes: 101604
from itertools import permutations as perm
from scipy.sparse.csgraph import dijkstra as di

def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]

n,m,r = map(int, input().split())
rr = [i-1 for i in map(int, input().split())]

inf = float('INF')
route = [[0 for j in range(n)] for i in range(n)]
for _ in range(m):
    a,b,c = map(int, input().split())
    route[a-1][b-1] = route[b-1][a-1] = c

route = di(route, n)

ans = inf
for tmp in perm(rr):
    cost = 0
    for i in range(r-1):
        cost += route[tmp[i]][tmp[i+1]]
    if cost < ans:
        ans = cost
print(int(ans))


Measured memory_bytes: 17008
#include <stdio.h>

int gcd(long long int x, long long int y)
{
    int z;
    while(y > 0){
        z = x % y;
        x = y;
        y = z;
    }
    return x;
}

int main(void)
{
    long long int a, b, g, l;

    while(scanf("%lld%lld",&a,&b)!= EOF){
        g = gcd(a,b);
        l = (a / g) * b;
        printf("%lld %lld\n",g,l);
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a*b<c){
		cout<<a*b<<endl;
	}
	else if(a*b>c){
		cout<<c<<endl;
	}
	else{
		cout<<c<<endl;
	}
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

double D(double a){
    return 360*(a/(2*M_PI));
}

void coord(double a, double &x, double &y, int r){
    x = cos(a)*r;
    y = sin(a)*r;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    cout << setprecision(20);

    double ha = (M_PI*(60*h + m))/360;
    double hx,hy;
    coord(ha, hx, hy, a);    
    double ma = (M_PI*m)/30;
    double mx,my;
    coord(ma, mx, my, b);
    double ans = (hx - mx)*(hx - mx) + (hy - my)*(hy - my);
    ans =sqrt(ans);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4188
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define pi atan(1) * 4

int main()
{
	int n;
	cin >> n;
	int p[100001];
	for(int i = 1; i <= n; i++){
		cin >> p[i];
	}
	int ans = 0;
	bool issame = (p[1] == 1);
	int cnt = 1;
	for(int i = 2; i <= n; i++){
		if(issame){
			if(p[i] == i){
				cnt++;
			} else {
				ans += (cnt + 1) / 2;
				issame = false;
				cnt = 1;
			}
		} else {
			if(p[i] != i){
				cnt++;
			} else {
				issame = true;
				cnt = 1;
			}
		}
	}
	if(issame){
		ans += (cnt + 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  char a,b,c,d;
  int count=0;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  if(d==a){
    count++;
  }
  cin >> d;
  if(d==b){
    count++;
  }
  cin >> d;
  if(d==c){
    count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <queue>
#define REP(i, n) for(int i = 1; i < n+1; i++)
using ll = long long;
using namespace std;


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int k;
    cin >> k;
    ll tmp=0;
    
    queue<ll> a;

    REP(i,9){
        a.push(i);
    }

    REP(i, k-1){
        tmp = a.front();
        
        if(tmp%10 == 0){
            a.push(10*tmp);
            a.push(10*tmp + 1);
        } else if(tmp%10 == 9){
            a.push(10*tmp+8);
            a.push(10*tmp+9);
        } else {
            a.push(10*tmp+(tmp%10-1));
            a.push(10*tmp+tmp%10);
            a.push(10*tmp+(tmp%10+1));
        }
        a.pop();
    }
    
    cout << a.front() << endl;
   
}


Measured memory_bytes: 1792
#pragma G++ optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#define INF 0x3f3f3f3f
#define NO 30005
#define MO 100005
typedef long long ll;
using namespace std;
inline ll read()
{
	char ch = ' ', last;
	ll ans = 0;
	while (ch < '0' || ch > '9')
		last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')
		ans = ans * 10 + int(ch - '0'), ch = getchar();
	if (last == '-')
		return -ans;
	return ans;
}
void write(ll x)
{
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + '0');
}
//head

int a, b, t;
//variable

void init()
{
	a = read(), b = read(), t = read();
}
//functions

int main()
{
	init();
	cout << b * int((t + 0.5) / a) << endl;
	return 0;
}
//main

Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val X, K, D = in.nextLong
  val x = math.abs(X)
  val n = x / D
  val r = x % D

  println(
    if (n >= K) x - K * D
    else {
      if ((K - n) % 2 == 1) D - r
      else r
    }
  )
}

Measured memory_bytes: 55284
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz jzm
#define ll long long
#define ull unsigned ll
const ll PR=19260817;
const int N=100005;
int n;
vector<int> g[N];
int sz[2][N], fa[2][N], dep[2][N];
void dfs(int ty, int u, int lst) {
	sz[ty][u]=1;
	fa[ty][u]=lst;
	if (lst!=-1)dep[ty][u]=dep[ty][lst]+1;
	for (int i=0; i<g[u].size(); i++) {
		int v=g[u][i];
		if (v==lst)
			continue;
		dfs(ty, v, u);
		sz[ty][u]+=sz[ty][v];
	}
}
int main() {
	scanf("%d", &n);
	for (int i=0; i<n-1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--, y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	fa[0][0]=-1;fa[1][n-1]=-1;
	dep[0][0]=0;dep[1][n-1]=0;
	dfs(0, 0, -1);
	dfs(1, n-1, -1);
	int ans[2];
	for (int _=0; _<2; _++) {
		int i=(_==1?0:n-1);
		int cc=(i==0?dep[1][i]-1-((dep[1][i]-1)/2):(dep[0][i]-1)/2);
		while (cc--) {
			i=fa[_][i];
		}
		ans[_]=sz[_][i]-1;
	}
	if (ans[0]<ans[1]) {
		puts("Fennec");
	} else {
		puts("Snuke");
	}
	return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
 
      if(A>12){
    System.out.println(B);
      }else if(A<=12 && A>5){
	System.out.println(B/2);
      }else{
    System.out.println("0");      
      }
      }
}

Measured memory_bytes: 22612
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli ma, n;
    cin>>n;
    bool c=true,rec=false;
    vi h(n);
    rep(i,n){
        cin>>h[i];
    }
    reverse(all(h));
    rep(i,n-1){
        if(h[i]<h[i+1]){ 
            if(h[i+1]-h[i]==1){ 
                h[i+1]--;
            }
            else{ 
                c=false;
                break;
            }
        }
    }
    Yes(c);
}

Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int N; cin >> N;
	cout << N/3 << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class Program{
    public static void Main(){
        int[] A=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        int a=A[1]-A[0]+1;
        Console.Write(a);
        for(int i=1;i<A[0]*2-1;i++){
            Console.Write(" ");
            Console.Write(a+i);
        }
    }
}


Measured memory_bytes: 13396
#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 INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

int n;
bool prime[1000005];

int main()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	for (int i = 2; i*i < 1000005; i++)
	{
		if (prime[i])
		{
			for (int j = 2; i*j < 1000005; j++)
			{
				prime[i*j] = false;
			}
		}
	}
	int a, d, n;
	while (cin >> a >> d >> n, a)
	{
		int cnt = 0;
		while (1)
		{
			if (prime[a])
			{
				cnt++;
				if (cnt == n)
				{
					cout << a << endl;
					break;
				}
			}
			a += d;
		}
	}

	return 0;
}

Measured memory_bytes: 2144
import sys, math
from math import factorial
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from bisect import bisect_left

sys.setrecursionlimit(10**7)
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))


orderP = 1
chk = []
for i, p in enumerate(P):
    chk_tmp = [1 if val < p else 0 for val in chk]
    cnt = sum(chk_tmp)
    orderP += (p - 1 - cnt) * factorial(N-(i+1))
    chk.append(p)    
    
orderQ = 1
chk = []
for i, q in enumerate(Q):
    chk_tmp = [1 if val < q else 0 for val in chk]
    cnt = sum(chk_tmp)
    orderQ += (q - 1 - cnt) * factorial(N-(i+1))
    chk.append(q)    

print(abs(orderP-orderQ))



Measured memory_bytes: 3424
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

int main(void){
	string s="";
	char cs[16];
	scanf("%s",cs);
	int len=strlen(cs);
	for(int i=0;i<len;i++){
		if(cs[i]=='B'){
			if(s.size()>0) s.pop_back();
		}
		else s+=cs[i];
	}
	puts(s.c_str());
}

Measured memory_bytes: 256
n = input()
m = input()
maxr = m.count("R")
maxw = m.count("W")

min_move = len(m)
max_r = m.count("R")
max_w = m.count("W")
right = 0
left = 0
for i in range(len(m)):
    if m[i] == "W":
        left += 1
    else:
        max_r -= 1
    if max(left,max_r) < min_move:
        min_move = max(left,max_r)
if maxw == 0 or maxr == 0:
    print(0)
else:
    print(min_move)

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

using namespace std;
using ll = long long;

int main()
{
    ll n, c;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n - 1; i++)
    {
        cin >> arr[i];
    }
    c = arr[0] + arr[n - 1 - 1];
    for (int i = 0; i < n - 1 - 1; i++)
    {
        c += min(arr[i], arr[i + 1]);
    }
    cout << c << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <iostream>
using i64 = long long;
template<i64 M> struct modint { i64 a;
  constexpr modint(const i64 x = 0): a((x%M+M)%M){}
  constexpr i64 value() const { return a; }
  constexpr modint inv() const { return this->pow(M-2); }
  constexpr modint pow(i64 r) const {
    modint ans(1); modint aa = *this;
    while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; }
    return ans;
  }
  constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; }
  constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; }
  constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; }
  constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; }
  constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; }
  constexpr modint operator+(const modint r) const { return modint(*this) += r; }
  constexpr modint operator-(const modint r) const { return modint(*this) -= r; }
  constexpr modint operator*(const modint r) const { return modint(*this) *= r; }
  constexpr modint operator/(const modint r) const { return modint(*this) /= r; }
  constexpr bool operator!=(const modint r) const { return this->value() != r.value(); }
};

template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; }

using fp = modint<(i64)(1e9 + 7)>;

int main() {
  i64 N, A, B;
  cin >> N >> A >> B;
  if(A > B) swap(A, B);
  // A <= B
  vector<fp> res(N + 2);
  {
    vector<fp> dp(N + 2);
    vector<fp> add(N + 2);
    dp[0] = fp(1);
    for(int i = 0;i < N; i++) {
      dp[i] += add[i];
      add[i + 1] += add[i];
      res[i + 1] += res[i];
      res[i] += dp[i];

      dp[i + 1] += dp[i];
      // +A
      if(i + A <= N){
        res[i + A] += dp[i];
        add[i + A + 1] += dp[i];
      }
    }
    dp[N] += add[N];
    res[N] += dp[N];
  }

  fp ans(0);
  {
    auto dp = ndvec(N + 1, 2, fp());
    rep(i,1,N) {
      // 0
      if(i < A) dp[i][0] += fp(1);
      rep(j,1,min(i, A)) dp[i][0] += dp[i - j][1];

      // 1
      if(i < B) dp[i][1] += res[i - 1];
      rep(j,1,min(i, B)) {
        fp w = (j == 1 ? 1 : res[j - 2]);
        dp[i][1] += dp[i - j][0] * w;
      }
      if(N - i < B) ans += dp[i][0] * res[N - i - 1];
      if(N - i < A) ans += dp[i][1];
    }
  }
  cout << fp(2).pow(N) - ans << endl;
}


Measured memory_bytes: 3872
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w[300];
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>w[i];
    int dp[300][300]={};
    int ans=0;
    for(int i=1;i<n;i++)dp[i][i-1]=0;
    for(int i=1;i<n;i++)
      for(int j=0;j+i<n;j++){
	for(int k=j;k<j+i;k++)
	  dp[j][j+i]=max(dp[j][j+i],dp[j][k]+dp[k+1][j+i]);
	if(dp[j+1][j+i-1]==i-1&&abs(w[j]-w[j+i])<2)dp[j][j+i]=i+1;
      }
    cout<<dp[0][n-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3404
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	for(cin>>n;n--;){
		string a,b;
		cin>>a>>b;
		int f=0;
		if(a.size()<b.size())swap(a,b);
		while(a.size()>b.size())b="0"+b;
		for(int i=a.size()-1;i>=0;i--){
			a[i]+=(b[i]-'0'+f);
			if(a[i]>'9'){
				f=1;
				a[i]-=10;
			}
			else f=0;
		}
		if(f)a="1"+a;
		cout<<(a.size()>80?"overflow":a)<<endl;
	}
	return 0;
}


Measured memory_bytes: 1216
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<ll> leaf(n + 1);
	for (int i = 0; i <= n; ++i) {
		cin >> leaf[i];
	}
	if (leaf[0] >= 2) {
		cout << -1 << '\n';
		return 0;
	}
	vector<ll> sum(n + 2);
	for (int i = 1; i <= n + 1; ++i) {
		sum[i] = sum[i - 1] + leaf[i - 1];
	}
	vector<ll> n_leaf(n + 1);
	n_leaf[0] = 1 - leaf[0];
	for (int i = 1; i <= n; ++i) {
		n_leaf[i] = (2LL * n_leaf[i - 1]) - leaf[i];
		n_leaf[i] = min(n_leaf[i], sum[n + 1] - sum[i + 1]);
		if (n_leaf[i] < 0) {
			cout << -1 << '\n';
			return 0;
		}
	}
	ll ans = 0;
	for (int i = 0; i <= n; ++i) {
		ans += leaf[i] + n_leaf[i];
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 5436
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
  int a,in,dsu=0;
  scanf("%d",&a);
  in=a;
  while(a!=0){
    dsu+=a%10;
    a/=10;
  }
  if(in%dsu==0) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 128
def main():
    a,b,c,k = map(int,input().split())
    plus_one = min(a,k)
    k -= plus_one
    zero = min(b,k)
    k -= zero
    minus_one = min(c,k)
    print(plus_one * 1 + zero * 0 + minus_one * (-1))



if __name__ == '__main__':
    main()



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

public class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int mochis = Integer.parseInt(br.readLine());
        Set<Integer> mochi = new HashSet<Integer>();

        for(int i = 0; i<mochis; i++){
            mochi.add(Integer.parseInt(br.readLine()));
        }
        System.out.println(mochi.size());
    }    
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  
  int A, B;
  cin >> A >> B;
  
  for(int i=1; i<1010; i++){
    int c = i * 0.08;
    int d = i * 0.1;
    if(c == A && d == B){
      cout << i << endl;
      return 0;
    }
  }
  
  cout << -1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		ArrayList<Task> tasks = new ArrayList<>();

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			Task task = new Task(name, second);
			tasks.add(task);
		}
		int time = 0;
		while (tasks.size() != 0) {
			Task task = tasks.get(0);
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);
				tasks.remove(0);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks.add(task);
				tasks.remove(0);
			}

		}

	}

}

class Task {
	String name;
	int second;

	public Task(String name, int second) {
		this.name = name;
		this.second = second;

	}

	public String getName() {
		return name;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}
}

Measured memory_bytes: 72840
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e10+10;

/*----------------------------------------------*/

signed main(){
  int n,m;
  cin>>n>>m;
  if(abs(n-m)>1){
    cout<<0<<endl;
    return 0;
  }
  int ans=1;
  FOR(i,1,n){
    ans*=i;
    ans%=MOD;
  }
  FOR(i,1,m){
    ans*=i;
    ans%=MOD;
  }
  if(n==m) ans*=2;
  ans%=MOD;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
int N,M;
map<pint,int>table;
int cur;
vpint G[1000000];
 
int make(int a,int c){
    if(table.count({a,c}))return table[{a,c}];
    table[{a,c}]=cur;
    G[a].pb({cur,1});
    G[cur].pb({a,0});
    return cur++;
}
int dist[1000000];
 
signed main(){
    cin>>N>>M;
    cur=N;
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        a=make(a,c);
        b=make(b,c);
        G[a].pb({b,0});
        G[b].pb({a,0});
    }
 
    fill_n(dist,cur,1001001001);
    dist[0]=0;
    priority_queue<pint>que;
    que.push({0,0});
    while(que.size()){
        int v,c;
        tie(c,v)=que.top();que.pop();
        c=-c;
        if(dist[v]<c)continue;
        for(auto e:G[v]){
            if(dist[e.fi]<=c+e.se)continue;
            dist[e.fi]=c+e.se;
            que.push({-dist[e.fi],e.fi});
        }
    }
 
    if(dist[N-1]==1001001001)cout<<-1<<endl;
    else cout<<dist[N-1]<<endl;
    return 0;
}

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


int main() {
	//(1)
	//string a, b, c;
	int array[3];
	cin >> array[0] >> array[1] >> array[2];

	sort(array,array+3);
	int max = array[2] * 10 + array[0] + array[1];

	
	cout << max << endl;
	
	
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(s) for s in input().split()]

print(' '.join([str(item) for item in A]))
for i in range(1, N):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Measured memory_bytes: 7728
N=int(input())
ab=[]
for i in range(N-1):
  ab.append(list(map(int, input().split())))
A=[ [] for i in range(N) ]
for i in range(N-1):
  A[ab[i][0]-1]+=[ab[i][1]-1]
  A[ab[i][1]-1]+=[ab[i][0]-1]

def BFS(i,A):
  dist=[0]*N
  d=[-1]*N
  d[i]=0#未訪問ならd=-1,訪問済みならiからの距離
  que=[i]
  dist=1
  while que:
    for j in range(len(que)):
      label=que.pop(0)
      for i in range(len(A[label])):
        if d[A[label][i]]==-1:
          d[A[label][i]]=dist
          que+=[A[label][i]]
    dist+=1
  return(d)

dist1=BFS(0,A)
dist2=BFS(N-1,A)
Fe=0
Su=0
for i in range(N):
  if dist1[i]<=dist2[i]:
    Fe+=1
  else:
    Su+=1
if Fe>Su:
  print("Fennec")
else:
  print("Snuke")

Measured memory_bytes: 49564
#!/usr/bin/env python
# coding: utf-8

# In[1]:


K, S = map(int, input().split())


# In[9]:


count = 0


# In[10]:


for_range = min(K+1, S+1)
for x in range(for_range):
    for y in range(for_range):
        if x+y >= S-K and x+y <= S:
            #print(x, y)
            count += 1


# In[11]:


print(count)


# In[ ]:






Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char ar[maxn];
int main(void)
{
	int T, N, K;
	// cin >> T;
	// while (T--) {
	cin >> N >> K;
	cin >> (ar + 1);
	int cnt = 0;
	for (int i = 2; i <= N; ++i) {
		if (ar[i] == ar[i - 1])
			cnt++;
	}
	cout << min(N - 1, cnt + 2 * K) << endl;
	// }

	return 0;
}

Measured memory_bytes: 384
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

s = input_s
t = input_s

if t[0..-2] == s
  puts "Yes"
else
  puts "No"
end


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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)

/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)

/* debug */
#define pp(v) cerr << #v "=" << (v) << endl;

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using vs = vector<string>;
using Graph = vvi;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* iostream */
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template<class T> T div_ceil(const T &a, const T &b) { return (a + b - 1) / b; }

signed main() {
  int n;cin>>n;
  vi a(n);cin>>a;
  vi ans;
  int m = n - 1;
  while (m > 0) {
    ans.pb(a[m]);
    m -= 2;
  }
  ans.pb(a[0]);
  m = n % 2 == 0 ? 2 : 1;
  while (m < n) {
    ans.pb(a[m]);
    m += 2;
  }
  rep(i,n) cout << ans[i] << " ";
  cout << endl;
}



Measured memory_bytes: 5488
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2 == 0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()
    


Measured memory_bytes: 7000
#include <iostream>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.length();i++)
	{
		int k=s[i]-'A';
		cout<<(char)((k+n)%26+'A');
	}
	return 0;
}

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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define NL printf("\n")
#define Max 505
#define INF 1e9
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())
#define mod 1000000007

#define FI freopen("in.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n,int pos)
{
    return (bool)(n & (1 << pos));
}

LL bigmod(LL b,LL p,LL m)
{
    if( p == 0 ) return 1;
    LL ret = bigmod(b,p/2,m);
    ret = ( ret * ret ) % m;
    if( p & 1 ) ret = ( ret * b ) % m;
    return ret;
}

int main()
{
    int n,a,b;
    siii(n,a,b);
    if( !( (b-a) & 1 ) ) puts("Alice");
    else puts("Borys");
    return 0;
}


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

typedef long long ll;
const int maxn = 1e6 + 5, mod = 1e9 + 7;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int n, sum, ans, f[maxn];

int main()
{
	n = gi();
	sum = f[0] = 1;
	ans = ((ll)(n - 1) * (n - 1) + 1 + (n > 2)) % mod;
	for (int i = 1; i < n; ++i) {
		f[i] = sum;
		if (i >= 2) f[i] = (f[i] + mod - f[i - 2]) % mod;
		sum = (sum + f[i]) % mod;
		if (i != n - 1) ans = (ans + (ll)f[i] * ((ll)(n - 1) * (n - 1) % mod + min(n - 1, i + 2))) % mod;
		else ans = (ans + (ll)f[i] * n) % mod;
	}
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
int main(){
    int n;std::cin>>n;
    int N=1;while(N<n)N*=2;
    std::vector<std::vector<int>>seg(26,std::vector<int>(2*N));
    std::vector<int>a(n);
    for(int i=0;i<n;i++){
        char c;std::cin>>c;
        seg.at(c-'a').at(N+i)++;
        a.at(i)=c-'a';
    }
    for(int i=0;i<26;i++){
        for(int j=N-1;j>0;j--){
            seg.at(i).at(j)=seg.at(i).at(2*j)+seg.at(i).at(2*j+1);
        }
    }
    auto add=[&](int i,int j,int x){
        j+=N;
        auto&&v=seg.at(i);
        v.at(j)+=x;
        for(j/=2;j>0;j/=2)v.at(j)=v.at(2*j)+v.at(2*j+1);
    };
    auto query=[&](int i,int l, int r){
        int ans=0;
        for(l+=N,r+=N;l<r;l/=2,r/=2){
            if(l%2==1)ans+=seg.at(i).at(l++);
            if(r%2==1)ans+=seg.at(i).at(--r);
        }
        return ans;
    };
    int q;std::cin>>q;
    for(int ngtkana_is_a_genius=0;ngtkana_is_a_genius<q;ngtkana_is_a_genius++){
        int ty;std::cin>>ty;
        if(ty==1){
            int i;char c;std::cin>>i>>c;
            i--;
            add(a.at(i),i,-1);
            add(c-'a',i,+1);
            a.at(i)=c-'a';
        }
        if(ty==2){
            int l,r;std::cin>>l>>r;
            l--;
            int ans=0;
            for(int i=0;i<26;i++){
                ans+=(bool)query(i,l,r);
            }
            std::cout<<ans<<std::endl;
        }
    }
}



Measured memory_bytes: 110976
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {
        ll n;
        cin>>n;
        vi v(n);
        ll rsum=0,lsum=0;
        fo(i,n)
            {cin>>v[i];rsum+=v[i];}
        lsum=v[0];
        rsum-=v[0];
        ll minsum=abs(lsum-rsum);
        for(ll i=1;i<n-1;i++)
        {

            lsum+=v[i];
            rsum-=v[i];
            minsum=min(minsum,abs(lsum-rsum));
        }

        cout<<minsum;


//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 4788
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 

const int MOD = 1000000007;

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

    vector<LL> a(N);
    LL s = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        s ^= a[i];
    }

    for (int i = 0; i < N; ++i) {
        a[i] &= ~s;
    }

    vector<int> top(N);
    int r = 0;
    for (int i = 60; 0 <= i; --i) {
        int j = r;
        for (; j < N; ++j) {
            if ((a[j]>>i)&1) {
                swap(a[r], a[j]);
                break;
            }
        }
        if (j == N) continue;
        top[r] = i;
        for (int k = 0; k < N; ++k) {
            if (k != r && ((a[k]>>i) & 1)) {
                a[k] ^= a[r];
            }
        }
        ++r;
    }

    LL x = 0;
    for (int i = 60; 0 <= i; --i) {
        LL nx = x | (1LL << i);
        LL b = nx;
        for (int j = 0; j < r; ++j) {
            if (b>>top[j]&1) {
                b ^= a[j];
            }
            if ((b&nx) == 0) {
                x = nx;
            }
        }
    }

    LL ans = s + x * 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
object Main {
  def main(args: Array[String]): Unit = {
    io.Source.stdin.getLines foreach (n => println(pi(n.toInt)))
  }
  val primes: IndexedSeq[Int] = prime_sieve(1000000)
  val pi_cache: collection.mutable.Map[Int, Int] = collection.mutable.Map.empty
  val phi_cache: collection.mutable.Map[(Int, Int), Int] = collection.mutable.Map.empty

  def prime_sieve(x: Int): IndexedSeq[Int] = {
    val n = x - x % 6 + 6
    val correction = if (x % 6 > 1) 1 else 2
    val sieve = Array.fill(n/3)(true)
    for (i <- 1 to (Math.sqrt(n) / 3).toInt if sieve(i)) {
      val k = (3 * i + 1) | 1
      for (j <- (k * k) / 3 until sieve.length by 2*k) sieve(j) = false
      for (j <- (k*(k-2*(i&1)+4))/3 until sieve.length by 2*k) sieve(j) = false
    }
    2 +: 3 +: (for (i <- 1 until n / 3 - correction if sieve(i)) yield (3*i+1)|1)
  }
  def bisect(n: Int): Int = {
    def loop(left: Int, right: Int): Int = {
      val mid = (left + right) / 2
      if (primes(mid) <= n && n < primes(mid+1)) mid+1
      else if (n < primes(mid)) loop(left, mid)
      else loop(mid+1, right)
    }
    if (n < primes.head) 0
    else if (n >= primes.last) primes.length
    else loop(0, primes.length)
  }
  def pi(x: Int): Int =
    pi_cache.getOrElseUpdate(x,
      if (x <= primes.last) bisect(x)
      else {
        val a = pi(Math.sqrt(Math.sqrt(x)).toInt)
        val b = pi(Math.sqrt(x).toInt)
        val c = pi(Math.cbrt(x).toInt)
        var result = phi(x, a) + ((b + a - 2) * (b - a + 1)) / 2
        for (i <- a + 1 to b) {
          val w = x / primes(i - 1)
          val b_i = pi(Math.sqrt(w).toInt)
          result -= pi(w)
          if (i <= c)
            for (j <- i to b_i)
              result = result - pi(w / primes(j - 1)) + j - 1
        }
        result
      }
    )
  def phi(x: Int, a:Int): Int =
    phi_cache.getOrElseUpdate(
      (x,a),
      {
        if (a == 1) (x + 1) / 2
        else phi(x, a - 1) - phi(x / primes(a - 1), a - 1)
      }
    )
}

Measured memory_bytes: 52700
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<long long int>adp(N);
	vector<long long int>bdp(N);
	vector<long long int>cdp(N);
	int a, b, c;
	cin >> a >> b >> c;
	adp[0] = a;
	bdp[0] = b;
	cdp[0] = c;
	for (int i = 1; i < N; i++) {
		cin >> a >> b >> c;
		adp[i] = max(bdp[i - 1], cdp[i - 1]) + a;
		bdp[i] = max(adp[i - 1], cdp[i - 1]) + b;
		cdp[i] = max(bdp[i - 1], adp[i - 1]) + c;
	}
	cout << max({ adp.back(), bdp.back(), cdp.back() }) << endl;
	return 0;
} 

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  double N; ll A; cin >> N >> A;
  ll result = N, count = 2;
  while (N>=(1ull<<count)) {
    ll l = 0, r = 10^6;
    ll num = (ll)ceil(pow(N,(double)1/count));
    ll q = count; while (pow(num-1,q)*pow(num,count-q)<N) q--;
    result = min(result, num*count-q+A*(count-1));
    count++;
  }
  cout << result << endl;
  return 0;
}


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

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
		int n = sc.nextInt();
		int l = sc.nextInt();
		String[] s = new String[n];
		for(int i=0;i<n;i++) {
			s[i] = sc.next();
		}
		
		Arrays.sort(s);
		
		for(int i=0;i<n;i++) {
			System.out.print(s[i]);
		}
		
	}
}

Measured memory_bytes: 37304
n = int(input())
x = input().split()
a = 0
b = 1
if x.count('0') >= 1:
  print(0)
else:
  while a <= n - 1 and b <= 1000000000000000000:
    b = b * int(x[a])
    a += 1
  if b > 1000000000000000000:
    print(-1)
  else:
    print(b)

Measured memory_bytes: 19388
S=input()
T=input()
ans=len(T)
for i in range(len(S)-len(T)+1):
    s=S[i:i+len(T)+1]
    m=0
    for j in range(len(T)):
        if s[j]!=T[j]:
            m+=1
    ans=min(ans,m)
print(ans)

Measured memory_bytes: 9056
/* ***********************************************
Author        :caoyu01
Created Time  :2016/9/4 20:26:34
File Name     :a.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cle(x) memset(x,0,sizeof(x))
#define rep(i,x) for(int i=0;i<x;i++)
const int N=1000+10;
const double eps=1e-10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    ll a,b,c;
   	while(cin>>a>>b>>c)
   {
	   ll ans;
	   if(c&1)ans=a*b;
	   else ans=0;
	   if(a&1)ans=min(ans,b*c);
	   else ans=0;
	   if(b&1)ans=min(ans,a*c);
	   else ans=0;
	cout<<ans<<endl;	
   }	   
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k;
   int res=(h2-h1)*60+(m2-m1)-k;
   cout<<res<<endl;
   return 0;
}

Measured memory_bytes: 3636
N = int(input())
c = []
s = []
f = []

for i in range(N-1):
    _c, _s, _f = map(int, input().split())
    c.append(_c)
    s.append(_s)
    f.append(_f)


for i in range(N):
    sumTime = 0
    stationNumber = i
    #print("(●・▽・●)",stationNumber)
    while stationNumber < N - 1:
        #print("(●・▽・●)(●・▽・●)", stationNumber, sumTime)
        if sumTime <= s[stationNumber]:
            sumTime = s[stationNumber]

        if (sumTime - s[stationNumber]) % f[stationNumber] == 0:
            sumTime += c[stationNumber]
            stationNumber += 1
        else:
            sumTime += f[stationNumber] - (sumTime - s[stationNumber]) % f[stationNumber]

    print(sumTime)

Measured memory_bytes: 3064
r,c = map(int,input().split())

calc_table = []
res_table = []

for _ in range(r):
	calc_table = list(map(int,input().split()))
	num = 0
	for i in calc_table:
		num += i
	calc_table.append(num)
	print(" ".join(str(a) for a in calc_table))
	res_table.append(calc_table)

last_table = []
for j in range(c + 1):
	last_num = 0
	for k in range(r):
		last_num += res_table[k][j]
	last_table.append(last_num)
print(" ".join(str(a) for a in last_table))


Measured memory_bytes: 5680