akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Closeable;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AStillTBD solver = new AStillTBD();
        solver.solve(1, in, out);
        out.close();
    }

    static class AStillTBD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.next();
            if (s.compareTo("2019/04/30") <= 0) {
                out.println("Heisei");
            } else {
                out.println("TBD");
            }
        }

    }

    static class FastScanner implements Closeable {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public void close() {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}



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

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}

template <typename T>
struct Graph_ {
  int n;
  vector<vector<pair<int, T> > > edge;
  vector<T> dis;
  Graph_(int ns) {
    n = ns;
    edge.resize(n);
    dis.resize(n);
  }
  void dijkstra(int s){
    dijkstra(s, 0);
  }
  T dijkstra(int s, int t){
    // initialize
    fill(dis.begin(), dis.end(), -1);
    vector<bool> used;
    used.resize(n);
    fill(used.begin(), used.end(), false);
    dis[s] = 0;
    // dijkstra
    priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > q;
    q.push(make_pair(0, s));
    while(!q.empty()){
      pair<T, int> p = q.top(); q.pop();
      int at = p.second;
      T distance = p.first;
      if(used[at])continue;
      used[at] = true;
      for(auto itr = edge[at].begin(); itr != edge[at].end(); ++itr){
        int to = (*itr).first;
        T cost = (*itr).second;
        if(used[to])continue;
        if(dis[to] == -1 || dis[to] > distance + cost){
          q.push(make_pair(distance + cost, to));
          dis[to] = distance + cost;
        }
      }
    }
    return dis[t];
  }
  void adde(int at, int to, T cost){
    edge[at].push_back(make_pair(to, cost));
  }
  [[deprecated("This function takes O(edge[at].size()).")]]
    void remove(int at, int to){
      int index = -1;
      for(int i = 0; i < edge[at].size(); i++){
        if(edge[at][i].first == to){
          index = i;
          break;
        }
      }
      edge[at].erase(edge[at].begin() + index);
    }
};

typedef struct Graph_<int> GraphI;
typedef struct Graph_<ll> GraphL;
typedef struct Graph_<double> GraphD;

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  GraphL graph(n);
  rep(i, m){
    int a, b, d;
    cin >> a >> b >> d;
    graph.adde(a, b, d);
  }
  graph.dijkstra(r);
  rep(i, n){
    if(graph.dis[i] >= 0)cout << graph.dis[i] << endl;
    else cout << "INF" << endl;
  }
	return 0;
}



Measured memory_bytes: 19380
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let mut before = ' ';
    for c in s.chars() {
        if before == c {
            println!("Bad");
            return;
        }
        before = c;
    }
        println!("Good");
}


Measured memory_bytes: 4352
type op =
  | Plus
  | Minus
  | Id

let print_op = function
    Plus -> print_char '+'
  | Minus -> print_char '-'
  | Id -> ()

(* list_all 2 [true; false];;
 * - : bool list list =
 * [[true; true]; [false; true]; [true; false]; [false; false]] *)
(* olに含まれる要素で作れる長さnのリストすべてを返す *)
let rec list_all : int -> 'a list -> 'a list list  = fun n ol ->
  if n > 0 then
    List.fold_right (fun l ans ->
        List.fold_right
          (fun o xs ->
             (o :: l) :: xs)
          ol ans)
      (list_all (n - 1) ol) []
  else
    [[]]

let calc_op l opss =  
  let rec loop ans =
    (function
      | (x :: xs, o :: os) ->
      (match o with
          Plus -> loop (ans + x) (xs, os)
        | Minus -> loop (ans - x) (xs, os)
        | Id -> loop x (xs, os))
      | _ -> ans)
  in
  loop 0 (l, opss)  

let ic c = int_of_char c - int_of_char '0'

let () =
  let (a, b, c, d) = Scanf.sscanf (input_line stdin) "%c%c%c%c" (fun a b c d -> (ic a, ic b, ic c, ic d)) in
  let ops_lists = list_all 3 [Plus; Minus] in
  let ops_lists' = List.map (fun ops -> Id :: ops) ops_lists in
  let rec solve = function
      [] -> failwith "Not found"
    | ops :: opss ->
      if calc_op [a;b;c;d] ops = 7 then
        ops
      else
        solve opss
  in
  let ans = solve ops_lists' in
  List.iter2 (fun x op ->
      print_op op;
      print_int x) [a;b;c;d] ans;
  print_string "=7";
  print_newline ()


Measured memory_bytes: 384
#include <cstdio>
const int MAXN = 1E5+5;
int array[MAXN]{ };
int L, M, N;

int main()
{
	scanf(" %d%d", &N, &L); M = -1;
	for(int i = 1; i <= N; ++i)
	{
		scanf("%d", &array[i]);
		if(array[i-1]+array[i] >= L)
			M = i-1;
	}
	if(M != -1)
	{
		puts("Possible");
		for(int i = 1; i < M; ++i)
			printf("%d\n", i);
		for(int i = N-1; i >= M; --i)
			printf("%d\n", i);
	}
	else
		puts("Impossible");
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

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__) << "] "
 

signed main(){
	IOS;
	int n , k ; 
	cin >> n >> k ; 
	vector<bool>dp(k+1,false);
	int stone[n] ; 
	for(int& i : stone) cin >> i;
	for(int i=0;i<= k; i++){
		for(int j : stone){
			if( i-j >= 0 and !dp[i-j]) dp[i] = true;
		}
	}
	cout << ( dp[k]?"First":"Second" ) << endl; 
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,l;
  cin>>n>>m>>l;
  
  int a[101][101];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++) cin>>a[i][j];

  int b[101][101];
  for(int i=0;i<m;i++)
    for(int j=0;j<l;j++) cin>>b[i][j];

  long long c[101][101]={};
  for(int i=0;i<n;i++)
    for(int j=0;j<l;j++)
      for(int k=0;k<m;k++)c[i][j] += a[i][k] * b[k][j];

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      if(j) cout<<" ";
      cout<<c[i][j];
      }
   cout<<endl;
  }
return 0;
}


Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

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

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

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

	// long long?
	ll N, M;
	cin >> N >> M;

	ll Mcand = 1;
	ll i = 1;
	while (1) {
		if (M % i == 0) {
			if (M / i >= N) {
				Mcand = max(Mcand, i);
			}
			if (i >= N) {
				Mcand = max(Mcand, M / i);
			}
		}
		i++;
		if (i * i > M) {
			break;
		}
	}

	cout << Mcand << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n,m,l;
    scanf("%d %d %d",&n ,&m, &l);
    
    long long int a[100][100];
    for(int i = 0;i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%lld",&a[i][j]);
        }
    }
    
    long long int b[100][100];
    
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            scanf("%lld",&b[i][j]);
        }
    }
    
    long long int c[100][100];
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            c[i][j] = 0;
            for(int k = 0; k < m; k++){
                
                c[i][j] += a[i][k] * b[k][j];
                
            }
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            printf("%lld",c[i][j]);
            if(j + 1 != l){
                printf(" ");
            }
        }
        printf("\n");
    }
    
}



Measured memory_bytes: 2076
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

class Edge {
 public:
  ll cost;
  ll to, from;

};

template<class Len = int>
class Dijkstra {
 private:
  int n;

  std::vector<std::vector<std::pair<int, Len> > > edges;
 public:
  explicit Dijkstra(int n) : n(n), edges(n) {}

  void add_edge(int from, int to, Len cost) {
    edges[from].push_back(std::pair<int, Len>(to, cost));
  }

  std::vector<Len> solve(int source) {
    const Len inf = 1e16;
    typedef std::pair<Len, int> pi;
    std::vector<Len> d(n, inf);
    std::priority_queue<pi, std::vector<pi>, std::greater<pi> > que;
    que.push(pi(0, source));
    while (!que.empty()) {
      pi p = que.top();
      que.pop();
      int idx = p.second;
      if (d[idx] <= p.first) {
        continue;
      }
      d[idx] = p.first;
      for (int j = 0; j < edges[idx].size(); ++j) {
        que.push(pi(p.first + edges[idx][j].second, edges[idx][j].first));
      }
    }
    return d;
  }
};

int main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  Dijkstra<ll> dij(n);
  vector<Edge> edges;
  rep(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    dij.add_edge(a, b, c);
    dij.add_edge(b, a, c);
    ll aa = min(a, b);
    ll bb = max(a, b);

    Edge edge;
    edge.from = aa;
    edge.to = bb;
    edge.cost = c;
    edges.push_back(edge);
  }
  vector<vector<ll>> sol_dij(n);
  rep(i, n) {
    sol_dij.at(i) = dij.solve(i);
  }
  ll ans = 0;
  rep(i, m) {
    bool isFukumareru = false;
    rep(j, n - 1) {
      REP(k, j + 1, n) {
        if (sol_dij.at(j).at(edges.at(i).from) + edges.at(i).cost + sol_dij.at(edges.at(i).to).at(k)
            == sol_dij.at(j).at(k))
          isFukumareru = true;

      }
    }
    if (isFukumareru) ++ans;
  }

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


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
//prototype declaration

//gloval variable
double PI = 3.1415926535897932384626433;
int MOD = 10007;

int main(void){
    char s[101];
    scanf("%s", s);
    int l = strlen(s);
    printf("%c%d%c\n", s[0], l-2, s[l-1]);
    return 0;
}


Measured memory_bytes: 1684
#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    ll mod = 1e9 + 7;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll res = 1, temp1 = 1, temp2 = 1;
    for (int i = 0; i < n; i++) {
        res = res * 10 % mod;
        temp1 = temp1 * 9 % mod;
        temp2 = temp2 * 8 % mod;
    }
    res = res - 2 * temp1 + temp2;
    while (res < 0) res += mod;
    res = res % mod;
    cout << res << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a;
    string s;
    cin >> a >> s;
    if (a >= 3200) {
        cout << s << endl;
    }
    else {
        cout << "red" << endl;
    }
    return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()
{

    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    while(1)
    {

        if(x > y) break;
        ans++;
        x*=2;
    }
    cout << ans;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t=1,i,j,k=0,q,p,x,y,n,a,b,d;
    //cin>>t;
    while(t--)
    {
       cin>>n;
       vector<ll>v[n+5];
       for(i=0;i<n;i++)
       {
           cin>>x>>y;
           v[i].push_back(x);
           v[i].push_back(y);
       }
       ll f=0;
       for(i=0;i+2<n;i++)
       {
           for(j=i;j+2<n;j++)
           {
               if(v[j][0]==v[j][1]&&v[j+1][0]==v[j+1][1]&&v[j+2][0]==v[j+2][1])
               {
                   f=1;
                   break;
               }
           }
       }
       if(f==1)
       {
           cout<<"Yes"<<endl;
       }
       else
        cout<<"No"<<endl;
    }

    return 0;
}


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

int main(){
	int N, i;
	scanf("%d", &N);
	vector<int> A(N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	sort(A.begin(), A.end());
	for(i = 1; i < N; i++){
		if(A[i - 1] == A[i]){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int N,M,X;
int C[20],A[20][20],D[20];
int min_S=-1;

void f(int p,int S){
  int c=1;
  for(int i=1;i<=M;i++){
    if(D[i]<X) c=0;
  }
  if(c==1){
    if(min_S<0 || S<min_S){
      min_S=S;
      return;
    }
  }
  for(int i=p+1;i<=N;i++){
    for(int j=1;j<=M;j++){
      D[j]+=A[i][j];
    }
    f(i,S+C[i]);
    for(int j=1;j<=N;j++){
      D[j]-=A[i][j];
    }
  }
  return;
}

int main(){
  scanf("%d %d %d",&N,&M,&X);
  for(int i=1;i<=N;i++){
    scanf("%d",C+i);
    D[i]=0;
    for(int j=1;j<=M;j++){
      scanf("%d",&A[i][j]);
    }
  }
  f(0,0);
  printf("%d\n",min_S);
}

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

int main() {
  string line;
  cin >> line;
  int num = line.length();
  int number = atoi(line.c_str());
  int waru;
  for (int i = 0;i < num;i++) {
    waru += number % 10;
    number = number / 10;
  }
  number = atoi(line.c_str());
  
  if (number % waru == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

class Node(object):
    def __init__(self, num: int):
        self.num = num
        self.cnt = 0
        self.visited = False

def dfs(init_node: Node, graph: list):
    stack = [init_node]
    init_node.visited = True
    while stack:
        cur = stack.pop()
        for nex in graph[cur.num]:
            if nex.visited:
                cur.cnt += nex.cnt
                cur.visited = True
            else:
                stack.append(nex)

n, q = li()
nodes = [Node(i) for i in range(n)]
graph = [[] for _ in range(n)]

for _ in range(n-1):
    ai, bi = li_()
    graph[ai].append(nodes[bi])
    graph[bi].append(nodes[ai])

for _ in range(q):
    pi, xi = li()
    pi -= 1
    nodes[pi].cnt += xi

dfs(nodes[0], graph)

ans = [nodes[i].cnt for i in range(n)]
print(*ans)

Measured memory_bytes: 123120
N = int(input())
C = input()

WL = [0]
RR = [C.count('R')]

for i in range(0, N):
    if C[i] == 'R':
        WL.append(WL[i])
        RR.append(RR[i] - 1)
    else:
        WL.append(WL[i] + 1)
        RR.append(RR[i])

MM = N
for i in range(0, N + 1):
    MM = min(MM, (max(WL[i], RR[i])))
print(MM)

Measured memory_bytes: 18644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
// *max_element(all(d));
int solve(){ 
  ll a,b;
  cin >> a >> b;
  ll ans = 0;
  if(a == 1 || b == 1){
    cout << 1 << endl;
    return 0;
  }
  if(a % 2 == 0){
    if(b%2!= 0){
    ans += (a / 2) * ((b + 2 - 1) / 2);
    ans += (a / 2) * ((b + 2 - 1) / 2 - 1);
    }
    else{
      ans += a * (b / 2);
    }
  }
  else{
    if(b % 2 != 0){
    ans += ((a + 2 - 1) / 2) * ((b + 2 - 1) / 2);
    ans += (a - ((a + 2 - 1) / 2)) * (((b + 2 - 1) / 2) - 1);
    }
    else{
      ans += a * (b / 2);
    }
  }
  cout << ans << endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var S, T, U string
	var A, B int
	fmt.Scan(&S, &T)
	fmt.Scan(&A, &B)
	fmt.Scan(&U)
	if S == U {
		fmt.Println(A-1, B)
	} else {
		fmt.Println(A, B-1)
	}
}


Measured memory_bytes: 512
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

#define INF       (1000000000)
#define N_MAX     (1000)
#define PARAM_NUM  (3)

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

typedef struct {
  QWORD qwLooks;
  QWORD qwTasty;
  QWORD qwPopular;
}CAKE;

CAKE stCake[N_MAX];
int N, M;

void solve_main()
{
  vector<QWORD>  aqwAns;
  cin >> N >> M;

  REP(i, 0, N) {
    cin >> stCake[i].qwLooks >> stCake[i].qwTasty >> stCake[i].qwPopular;
  }

  REP(i, 0, 1 << PARAM_NUM) {
    QWORD  aqwParam[PARAM_NUM];
    vector<QWORD>  aqwPoints;
    QWORD  qwSum;
    aqwPoints.resize(N);
    for (int j = 0; j < PARAM_NUM; j++) {
      if (i & (1 << j)) {
        aqwParam[j] = 1;
      } else {
        aqwParam[j] = -1;
      }
    }

    REP(idx, 0, N) {
      aqwPoints[idx] = stCake[idx].qwLooks * aqwParam[0] + stCake[idx].qwTasty * aqwParam[1] + stCake[idx].qwPopular * aqwParam[2];
    }
    sort(aqwPoints.begin(), aqwPoints.end(), greater<QWORD>());
    qwSum = accumulate(aqwPoints.begin(), aqwPoints.begin() + M, 0LL);
    aqwAns.push_back(qwSum);
  }

  auto iter = max_element(aqwAns.begin(), aqwAns.end());

  cout << abs(*iter) << endl;
}

int main()
{
#ifdef FOR_IDE
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  solve_main();
  return 0;
}


Measured memory_bytes: 256
#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>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	int nodenum = n;
	vector<vector<pair<int, int> > > graph(n);
	map<pair<int, int>, int> ekiAndLineToNode;

	for(int i = 0; i < m; i++){
		int p, q, c;
		cin >> p >> q >> c;
		p--;
		q--;
		if(ekiAndLineToNode.find(make_pair(p, c)) == ekiAndLineToNode.end()){
			ekiAndLineToNode[make_pair(p, c)] = nodenum;
			graph.push_back(vector<pair<int, int> >());
			nodenum++;
		}
		if(ekiAndLineToNode.find(make_pair(q, c)) == ekiAndLineToNode.end()){
			ekiAndLineToNode[make_pair(q, c)] = nodenum;
			graph.push_back(vector<pair<int, int> >());
			nodenum++;
		}
		int pind = ekiAndLineToNode[make_pair(p, c)];
		int qind = ekiAndLineToNode[make_pair(q, c)];
		graph[pind].push_back(make_pair(qind, 0));
		graph[qind].push_back(make_pair(pind, 0));
		graph[pind].push_back(make_pair(p, 1));
		graph[p].push_back(make_pair(pind, 0));
		graph[qind].push_back(make_pair(q, 1));
		graph[q].push_back(make_pair(qind, 0));
	}
	priority_queue<pair<int, int> > qu;
	vector<int> result(nodenum, mod);
	qu.push(make_pair(0, 0));
	while(!qu.empty()){
		int node = (qu.top()).second;
		int cost = -(qu.top()).first;
		qu.pop();
		if(result[node] <= cost) continue;
		result[node] = cost;
		for(int i = 0; i < graph[node].size(); i++){
			int next = graph[node][i].first;
			int nextcost = graph[node][i].second + cost;
			if(nextcost < result[next]) qu.push(make_pair(-nextcost, next));
		}
	}
	if(result[n - 1] == mod) cout << -1 << endl;
	else cout << result[n - 1] << endl;
}

Measured memory_bytes: 60520
n=int(input())
s=input()
from collections import Counter
c=Counter(s)
w=c['W']
r=c['R']
if w==0 or r==0:
    print (0)
else:
    z=0
    for i in range(r):
        if s[i]=='W':
            z+=1
    print (z)

Measured memory_bytes: 9520
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < n; i += 2) {
    ans += a[i];
  }
  for (int i = 1; i < n; i += 2) {
    ans -= a[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for(int i=0;i<=a;i++) {
    for(int j=0;j<=b;j++) {
      for(int k=0;k<=c;k++) {
        if(500 * i + 100 * j + 50 * k == x) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
//与えられたn個の数列において各数列内での最大最小を求める
#include<iostream>
#include<algorithm>
#include<vector>

int main (){
    int a,b,e,n,m,com;
    std::cin>>n;
    std::vector<int> vec{};
    
    
    for(int i=0;i<n;i++){
        std::cin>>a;
        vec.push_back(a);
    }

    std::cin>>m;
    for(int j=0;j<m;j++){
        std::cin>>com>>b>>e;
        auto t = std::minmax_element(&vec[b],&vec[e]);        
        switch(com){
            case 0:{
                std::cout<<*t.first<<std::endl;
                break;
            }
            case 1:{
                std::cout<<*t.second<<std::endl;
                break;
            }
        }
    }

    return 0;
}



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

int main() {
  int a,b,c,ans=1;
  cin >> a >> b >> c;
  if(a!=b)
    ans++;
  if(a!=c)
    ans++;
  if(b==c)
    ans--;
  if(a==b&&b==c)
    ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
typedef double db;
const db eps = 1e-8;
inline int judge(db x) {
  return x > -eps ? x > eps ? 1 : 0 : -1;
}
struct point {
  db x,y;
  point(db x_=0,db y_=0): x(x_), y(y_) {}
  db operator * (const point& a) const {
    return x * a.y - y * a.x;
  }
  point operator + (const point& a) const {
    return point(x + a.x, y + a.y);
  }
  point operator - (const point& a) const {
    return point(x - a.x, y - a.y);
  }
  void operator += (const point& a) {
    *this = *this + a;
  }
  void operator -= (const point& a) {
    *this = *this - a;
  }
} q[N];
int n,cap,t,v,l=1,r;
point cur,tmp;
int main() {
  scanf("%d%d",&n,&cap);
  scanf("%d%d",&t,&v);
  printf("%d.00000000\n",t);
  q[++r] = point(v,1.0 * t * v);
  cur += point(v,1.0 * t * v);
  for (int i = 2 ; i <= n ; ++ i) {
    scanf("%d%d",&t,&v);
    db a = v;
    while (judge(a - q[l].x) >= 0)
      a -= q[l].x, cur -= q[l++];
    cur -= q[l];
    q[l].y *= (q[l].x - a) / q[l].x;
    q[l].x -= a;
    cur += q[l];
    tmp = point(v,1.0 * t * v);
    while (l <= r && judge(q[r] * tmp) <= 0)
      tmp += q[r], cur -= q[r--];
    if (judge(tmp.x - cap) > 0) {
      tmp.y *= cap / tmp.x;
      tmp.x = cap;
    }
    q[++r] = tmp;
    cur += tmp;
    printf("%.8lf\n",cur.y / cur.x);
  }
  return 0;
}

Measured memory_bytes: 17280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	long long h[n+1],f[n+1];
	for(int i=1;i<=n;i++) 
	{
		cin>>h[i];
	}
	f[1]=0;
	f[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++)
	{
		f[i]=f[i-1]+abs(h[i]-h[i-1]);
		for(int j=1;j<=k;j++) 
			if(i-j>=1)
			   f[i]=min(f[i-j]+abs(h[i]-h[i-j]),f[i]);
	} 
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1792
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m,v,p = inpl()
a = inpl()
c = Counter(a)
a.sort()
b_num = a[n-p]
d_cnt = 0
b_cnt = 0
u_cnt = 0
for i in a:
    if i < b_num: d_cnt += 1
    elif i == b_num: b_cnt += 1
    else: u_cnt += 1

def f(x,i):
    if x >= b_num:
        return True
    if x + m < b_num:
        return False
    if i + 1 + u_cnt >= v:
        return True
    cnt = 0
    for item in a:
        if item > b_num or item <= x:
            cnt += m
        else:
            cnt += x + m - item
    # print(cnt)
    if cnt >= m*v:
        return True
    else:
        return False
# print(f(a[2],2))
ok = n
ng = -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(a[mid],mid):
        ok = mid
    else:
        ng = mid
print(n-ok)


Measured memory_bytes: 96104
import java.io.BufferedReader
import java.util.*
import kotlin.math.min

fun main() = abc073d()

@OptIn(ExperimentalStdlibApi::class)
fun abc073d() = SimpleFastIOWithToken_abc073d().exec {
    data class Line(val first: Int, val second: Int, val weight: Long)
    data class Point(val index: Int, val neighbor: MutableSet<Int> = mutableSetOf())

    val (n, m, r) = List(3) { readInt() }
    val rList = List(r) { readInt() - 1 }
    val lines = List(m) { Line(readInt() - 1, readInt() - 1, readLong()) }

    val distances = Array(n) { LongArray(n) { Long.MAX_VALUE / 10000 } }
    lines.forEach { (first, second, weight) ->
        distances[first][second] = weight
        distances[second][first] = weight
    }

    for (k in 0 until n) for (i in 0 until n) for (j in 0 until n) {
        distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j])
    }

    val answer = permutations(rList).map { visitOrder ->
        (1 until r).map { distances[visitOrder[it - 1]][visitOrder[it]] }.sum()
    }.min()!!

    println(answer)
}

private fun permutations(src: List<Int>): List<List<Int>> {
    if (src.size == 1) return listOf(src)
    val perms = mutableListOf<List<Int>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for (i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc073d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc073d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


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

int main(void) {
	string S;
	cin >> S;
	bool hString = true;
	for (int i = 0; i < S.length(); i+=2) {
		if (S[i] !='h' || S[i+1] !='i') {
			hString = false;
		}
	}
	if (hString) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
  return 0;
}


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

using namespace std;

typedef long long ll;

template<typename T>
void _dump(const char* s, T&& head)
{
  cerr << s << "=" << head << endl;
}

template<typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail)
{
  while (*s != ',')
    cerr << *s++;
  cerr << "=" << head << ",";
  _dump(s + 1, tail...);
}

template<typename T>
void _dumpv(const char* s, T&& v)
{
  cerr << *s << "=";
  for (auto it = v.begin(); it != v.end(); it++) {
    cerr << *it << " ";
  }
  cerr << endl;
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__)
#define dumpv(...) _dumpv(#__VA_ARGS__, __VA_ARGS__)

const ll MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("template.1", "r", stdin);

  int W, H;
  cin >> W >> H;
  int w, h;
  cin >> w >> h;
  dump(W, H, w, h);
  vector<vector<int>> v = vector<vector<int>>(H, vector<int>(W, 0));
  for (int y = 0; y < H; y++) {
    dumpv(v[y]);
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < W; x++) {
      v[y][x] = true;
    }
  }
  for (int y = 0; y < H; y++) {
    dumpv(v[y]);
  }
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < w; x++) {
      v[y][x] = true;
    }
  }
  for (int y = 0; y < H; y++) {
    dumpv(v[y]);
  }
  int ans = 0;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (!v[y][x])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

//void print_lcs(int b[3000][3000], string x, int i, int j){
//	if(i == 0 || j ==0){
//		return;
//	}
//	if(b[i][j] == 0){
//		print_lcs(b, x, i-1, j-1);
//		cout<<x[i-1];
//	}
//	else if(b[i][j] == 1){
//		print_lcs(b, x, i-1, j);
//	}
//	else
//		print_lcs(b, x, i, j-1);
//}

void LCS(string x, string y){
	int m,n;
	m = x.length();
	n = y.length();
	int c[m+1][n+1];
	string z = "";
	for(int i=0; i<=m; i++){
		c[i][0] = 0;
	}
	for(int i=0; i<=n; i++){
		c[0][i] = 0;
	}
//	int b[3000][3000];
	for(int i=1; i<=m; i++){
	
		for(int j=1; j<=n; j++){
			if (x[i-1] == y[j-1]){
				c[i][j] = c[i-1][j-1]+1;
//				b[i][j] = 0;
//				break;
			}
			else if(c[i-1][j]>=c[i][j-1]){
				c[i][j] = c[i-1][j];
//				b[i][j] = 1;
			}
			else{
				c[i][j] = c[i][j-1];
//				b[i][j] = 2;			
				}
		}
	}
//	print_lcs(b, x, m, n);
	int i = m;
	int j = n;
	while(i >= 1 && j >= 1){
		if(c[i][j] > c[i-1][j] && c[i][j] > c[i][j-1]){
			z += x[i-1];
			i--; 
			j--;
		}
		else if(c[i-1][j] >= c[i][j-1]){
			i--;
		}
		else j--;
	}
	for(int p = z.length()-1; p>=0; p--)
		cout<<z[p];
	
}

int main(){
	string x, y;
	cin>>x>>y;
	LCS(x,y);
}

Measured memory_bytes: 35456
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

MIN = 10
ans = 0
for i in (A,B,C,D,E):
    if i % 10 != 0:
        MIN = min(MIN, i % 10)
        ans += i - i % 10 + 10
    else:
        ans += i
ans -= 10 - MIN
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll Dp[3030][3030];

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

    ll n = s.size();
    ll m = t.size();

    for(ll i=n-1;i>=0;i--)
        for(ll j=m-1;j>=0;j--)
            Dp[i][j] = max( max ( Dp[i][j+1] , Dp[i+1][j] ) , (ll)(s[i]==t[j]) + Dp[i+1][j+1] );

    for(ll i=0,j=0;i<n&&j<m;)
        if(Dp[i][j]==Dp[i][j+1])
            j++;
        else if(Dp[i][j]==Dp[i+1][j])
            i++;
        else
        {
            if(s[i]==t[j])  cout<<s[i];
            i++;j++;
        }

}


Measured memory_bytes: 71936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

template< typename T >
struct edge { int src, to;};
void bfs(int i, int j, string *s, int **d, int H, int W){
  if(i+1 < W && j < H){
    if(s[i+1][j]=='.') d[i+1][j] = d[i][j]+1;
  }
  if(j+1 < H && i < W){
    if(s[i][j+1]=='.') d[i][j+1] = d[i][j]+1;
  }
}
  
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H,W;
  cin >> H >> W;
  string s[H];
  rep(i,H) cin >> s[i];
  int d[H][W];
  int ans=H*W;
  rep(i,H) rep(j,W){
    d[i][j]=INT_MAX;
    if(s[i][j]=='#') ans--;
  }
  d[0][0]=0;
  queue<pair<int, int> >q;
  q.push(mp(0,0));
  while (!q.empty()) {
    pair<int, int> now = q.front(); q.pop();
    int i=now.first;
    int j=now.second;
    //    cout << i << " "<< j << endl;
    if(j < W && i+1 < H){
      if(s[i+1][j]=='.' && d[i+1][j]==INT_MAX){
	d[i+1][j] = d[i][j]+1;
	q.push(mp(i+1,j));
      }
    }
    if(i < H && j+1 < W){
      if(s[i][j+1]=='.' && d[i][j+1]==INT_MAX){
	d[i][j+1] = d[i][j]+1;
	q.push(mp(i,j+1));
      }
    }
    if(i < H && j-1 >=0){
      if(s[i][j-1]=='.' && d[i][j-1]==INT_MAX){
	d[i][j-1] = d[i][j]+1;
	q.push(mp(i,j-1));
      }
    }
    if(i-1 >=0 && j < W){
      if(s[i-1][j]=='.' && d[i-1][j]==INT_MAX){
	d[i-1][j] = d[i][j]+1;
	q.push(mp(i-1,j));
      }
    }
  }


    
  int dist=d[H-1][W-1];
  if(dist==INT_MAX) cout << -1 << endl;
  else   cout << ans-(dist+1) << endl;
    
  
  return 0;
    

}


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

int n, m;
int p[111111];
vector<int> e[111111];

struct DisjointSet{
  
  vector<int> rank, p;

  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for(int i=0;i<size;i++)makeSet(i);
  }
  
  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }
  
  bool same(int x, int y) {
    return findSet(x) == findSet(y);
  }
  
  void unite(int x, int y) {
    link(findSet(x), findSet(y));
  }
  
  void link(int x, int y) {
    if( rank[x] > rank[y] ) {
      p[y] = x;
    } else {
      p[x] = y;
      if( rank[x] == rank[y] ){
        rank[y]++; 
      } 
    }
  }
  
  int findSet(int x) {
    if( x != p[x] ) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  } 
};

int main(){
  ios_base::sync_with_stdio(false);
  
  int ans = 0;

  cin >> n >> m;
  for(int i=1;i<=n;i++){
    int num;
    cin >> num;
    p[num] = i;
  } 
  
  DisjointSet ds = DisjointSet(n+10);
  for(int i=0;i<m;i++){
    int x, y;
    cin >> x >> y;
    ds.unite(x, y);
  } 
  
  for(int i=1;i<=n;i++){
    if(ds.same(p[i], i))ans++;  
  } 
    
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4096
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

const int N=55;
const int M=N*N*N;
const ll inf=1000000000000000000ll;

struct node{
	ll sz,sum,lim;
	node(){}
	node(ll sz,ll sum,ll lim):sz(sz),sum(sum),lim(lim){}
}a[N];
struct E{
	int to,next;
}mem[N<<1];
int n,num,up;
ll x,d,lim,now,s,ans;
int w[N],fa[N],head[N];
ll sz[N],sum[N],dp[M];

void add(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num;
}

void dfs(int k,int pre){
	int j,u;
	sz[k]=1; sum[k]=w[k];
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		dfs(u,k);
		sz[k]+=sz[u]; sum[k]+=sum[u];
	}
}

bool cmp(node a,node b){
	return a.sum*b.sz<b.sum*a.sz;
}

int main(){
	int i,j,k;
	scanf("%d%lld%lld",&n,&x,&d);
	for (i=1;i<=n;i++){
		scanf("%d",&w[i]); 
		if (i>1){
			scanf("%d",&fa[i]);
			add(fa[i],i);
		}
	}
	dfs(1,0);
	for (i=1;i<=n;i++){
		if (i==1) lim=x;
		else lim=d-min(1ll*n,d);
		a[i]=node(sz[i],sum[i],lim);
	}
	for (i=1;i<=n*n*n;i++) dp[i]=inf;
	sort(a+1,a+1+n,cmp);
	for (i=1;i<=n;i++){
		if (i==1) up=n;
		else up=min(n,(int)d);
		for (j=n*n*n;j>=0;j--)
			for (k=0;k<=up&&k*sz[i]<=j&&k*sum[i]<=x;k++)
				dp[j]=min(dp[j],dp[j-k*sz[i]]+k*sum[i]);
	}
	for (j=n*n*n;j>=0;j--) if (dp[j]<=x){
		s=x-dp[j];
		now=j;
		for (i=1;i<=n&&s>0;i++){
			now+=min(s/a[i].sum,a[i].lim)*a[i].sz;
			s-=min(s/a[i].sum,a[i].lim)*a[i].sum;
		}
		ans=max(ans,now);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define abs(x) ((x)>0?(x):(-(x)))
using namespace std;

typedef long long LL;

int main(){
    ios::sync_with_stdio(false);
    LL X,Y;
    cin>>X>>Y;
    if(abs(X-Y)<=1) cout<<"Brown"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {

  public static void Main (string[] args) {
    var N = ReadLineInt();
    var L = ReadLineLongList();

    var ans = 0;
    if(L.Distinct().Count() == 1){
      ans = N / 2;
      Console.WriteLine(ans);
      return;
    }
 
   	var test = N / 2 - L.Where((x, i) => i % 2 == 0).GroupBy(g => g).Select((x, i) => x.Count()).Max();

    var test2 = N / 2 - L.Where((x, i) => i % 2 == 1).GroupBy(g => g).Select((x, i) => x.Count()).Max();


    var even = L.Where((x, i) => i % 2 == 0).GroupBy(g => g).Select(g => new { n = g.Key, c = g.Count()}).OrderByDescending(x => x.c).First();

    var odd = L.Where((x, i) => i % 2 == 1).GroupBy(g => g).Select(g => new { n = g.Key, c = g.Count()}).OrderByDescending(x => x.c).First();

    if(even.n == odd.n){
      var second = L.Where((x, i) => i % 2 == 0).GroupBy(g => g).Select(g => new { n = g.Key, c = g.Count()}).OrderByDescending(x => x.c).ElementAt(1);

      var second2 = L.Where((x, i) => i % 2 == 1).GroupBy(g => g).Select(g => new { n = g.Key, c = g.Count()}).OrderByDescending(x => x.c).ElementAt(1);
     
      ans = Math.Min( N / 2 - second.c  + test2, N / 2 - second2.c  + test);
    }else{
      ans = test + test2;
    }

    /*test.ToList().ForEach(Console.WriteLine);
    test2.ToList().ForEach(Console.WriteLine);*/
    Console.WriteLine(ans);
  }

  static int ReadLineInt() {
    return int.Parse(Console.ReadLine());
  }
 static string ReadLineString() {
    return Console.ReadLine();
  }
  static IEnumerable<long> ReadLineLongList() {
    return Console.ReadLine().Split(' ').Select(long.Parse);
  }

}

Measured memory_bytes: 46228
using System;
using System.Linq;
class c
{
    static void Main()
    {
        Console.ReadLine();
        var l = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).OrderBy(f => f);
        int ans = l.Where((f, g) => g % 2 == 0).Sum();
        Console.WriteLine(ans);
    }
}

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

int main() {
	string s;
    cin >> s;
    int n = s.size();
    if(n < 4 || s.substr(0, 4) != "YAKI") cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3604
n = int(input())
lson, rson = [-1]*n, [-1]*n
parent = [-1]*n
for i in range(n):
    id, ls, rs = map(int, input().split())
    lson[id], rson[id] = ls, rs
    if ls != -1:
        parent[ls] = id
    if rs != -1:
        parent[rs] = id
def pre_order(r):
    if r == -1: return
    print("", r, end = '')
    pre_order(lson[r])
    pre_order(rson[r])

def in_order(r):
    if r == -1: return
    in_order(lson[r])
    print("", r, end = '')
    in_order(rson[r])

def post_order(r):
    if r == -1: return
    post_order(lson[r])
    post_order(rson[r])
    print("", r, end = '')

for i in range(n):
    if parent[i] == -1:
        print("Preorder")
        pre_order(i)
        print("")
        print("Inorder")
        in_order(i)
        print("")
        print("Postorder")
        post_order(i)
        print("")


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


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

Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())

	ans := 0
	min := 99999999.0
	for i := 1; i <= n; i++ {
		sc.Scan()
		h, _ := strconv.Atoi(sc.Text())

		if d := math.Abs(float64(a-t) + 0.006*float64(h)); d < min {
			min = d
			ans = i
		}
	}
	fmt.Println(ans)
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
int n, m;
constexpr int r = 31;
struct Edge {
	int to;
	double cost;
};
int index(int v, int prev, int speed) {
	return v * n*r + prev * r + speed;
}
using Graph = vector<vector<Edge>>;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (cin >> n >> m, n) {
		int s, t; cin >> s >> t;
		s--; t--;
		Graph g(n * n * r);
		REP(aaaaaa, m) {
			int a, b, c, d;
			cin >> a >> b >> d >> c;
			a--; b--;
			REP(i, n) {
				REP(j, r) {
					for (int k = j - 1; k <= j + 1; ++k) {
						if (k > 0 && k <= c) {
							int from = index(a, i, j), to = index(b, a, k);
							if (b != i)g[index(a, i, j)].push_back({ index(b,a,k),double(d) / k });
							if (a != i)g[index(b, i, j)].push_back({ index(a,b,k),double(d) / k });
						}
					}
				}
			}
		}
		vector<double> dist(n*n*r, INF);
		using P = pair<double, int>;
		priority_queue<P, vector<P>, greater<>> q;
		REP(i, n) {
			int j = index(s, i, 0);
			dist[j] = 0;
			q.push({ 0,j });
		}
		while (!q.empty()) {
			auto p = q.top(); q.pop();
			int v = p.second;
			if (p.first - EPS > dist[v])continue;
			REP(i, g[v].size()) {
				int to = g[v][i].to;
				if (dist[to] - EPS > dist[v] + g[v][i].cost) {
					dist[to] = dist[v] + g[v][i].cost;
					q.push({ dist[to],to });
				}
			}
		}
		double ans = INF;
		REP(i, n)chmin(ans, dist[index(t, i, 1)]);
		if (ans == INF)cout << "unreachable" << endl;
		else cout << fixed << setprecision(12) << ans << endl;
	}
}


Measured memory_bytes: 58936