akhauriyash/Code-Regression huggingface dataset:
while line = gets
  p, q = line.chomp.split.map(&:to_i)

  n = nil
  mods = []
  nums = []

  until p == 0
    p = p * 10
    break if n = mods.index(p)
    mods << p
    nums << p / q
    p = p % q
  end

  puts nums.join
  unless n == nil
    stack = []
    stack.fill(' ', 0...n)
    stack.fill('^', n...nums.size)
    puts stack.join
  end
end

Measured memory_bytes: 8860
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a - b < c ? c - a + b : 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int A = 1000001;

int n, s[A], f[A], mod = 998244353;

int powlog(int a, int b){
    if(b == 0) return 1;
    int ret = powlog(a, b / 2);
    if(b % 2) return 1LL * ret * ret % mod * a % mod;
    return 1LL * ret * ret % mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        s[x] += x;
        if(s[x] >= mod) s[x] -= mod;
        ans -= x;
        if(ans < 0) ans += mod;
    }
    for(int i = 1 ; i < A ; i++){
        for(int j = i ; j < A ; j += i){
            f[i] += s[j];
            if(f[i] >= mod) f[i] -= mod;
        }
        f[i] = 1LL * f[i] * f[i] % mod;
    }
    for(int i = A - 1 ; i >= 1 ; i--){
        for(int j = i + i ; j < A ; j += i){
            f[i] -= f[j];
            if(f[i] < 0) f[i] += mod;
        }
        ans = (ans + 1LL * f[i] * powlog(i, mod - 2)) % mod;
    }
    cout << 1LL * ans * powlog(2, mod - 2) % mod << endl;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n,k ;
int arr[500005] ;
vector<int> v ;
int vis[500005] ;
vector<int> temp ;
void solve()
{
    cin >> n >> k ;
    for(int i=1 ; i<=n ; i++)
        cin >> arr[i] ;
    v.pb(1) ;
    vis[1] = 1 ;
    int last = 1 ;
    int num = 1 ;
    while(1)
    {
        int t = arr[last] ;
        if(vis[t])
        {
            num = t ;
            break ;
        }
        vis[t] = 1 ;
        v.pb(t) ;
        last = t ;
    }
    //cout << "H\n" ;
    if(k<(int)(v.size()))
    {
        cout << v[(k)%(int)(v.size())] ;
        return ;
    }
    int i = 0 ;
    while(i<v.size()&&v[i]!=num)
        i++ ;
    while(i<v.size()){
        temp.pb(v[i]) ;
        i++ ;
    }
    int dif = (int)(v.size()) - (int)(temp.size()) ;
    k -= dif ;
    k %= (int)(temp.size()) ;
    cout << temp[(k)%(int)(temp.size())] ;

}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}


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

class Main{
	public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
   int data[]=new int[100];
   int m=0;
   while(sc.hasNext()){
	   int n=sc.nextInt()-1;
	   data[n]++;
	   if(m<data[n]) m=data[n];
   }
 for(int i=0; i<data.length; i++){ 
	 if(data[i]==m) System.out.println(i+1);
 }
	}
	}

Measured memory_bytes: 18104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }

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

    int N,K; cin >> N >> K;
    vel x(N); rep(i,N) cin >> x[i];

    ll ans = INF;
    rep(i,N-K+1) {
        if( abs(x[i]) < abs(x[i+K-1]) ){
            ll temp = abs(x[i]) + abs(x[i+K-1] - x[i]);
            ans = min(ans, temp);
        }
        else {
            ll temp = abs(x[i+K-1]) + abs(x[i+K-1] - x[i]);
            ans = min(ans, temp);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
}
int main(void)
{
    lli A, B, N;
    cin >> A >> B >> N;
    if (B > N)
    {
        cout << (lli)((A * (N)) / B);
    }
    else
    {
        cout << (lli)((A * (B - 1)) / B);
    }
    return 0;
}

Measured memory_bytes: 3628
h={};t={}
`read a;factor`.lines.map{|e|x=y=1
e.gsub(/( \d+)\1*\b/){|m|x*=(n=m.to_i)**(a=m.count(' ')%3);y*=n**(-a%3)}
h[x]=1.+h[x]||0;t[x]=y}
h[1]&&=1
h.keys.map{|k|$.+=[h[k],h[t[k]]||0].max;h[k]=h[t[k]]=0}
p$.

Measured memory_bytes: 57484
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long



signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,Y; cin >> n >> Y;
    
    for(int x = 0;x <n+1;x ++){
        for(int y = 0;y < n+1;y ++){
            int z = Y - x * 10000 - y * 5000;
            z /= 1000;
            if(0 <= z && x + y + z == n){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
}

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

using namespace std;

int main()
{
    char text[1001];
    cin.get(text, 1001);
    int a, b, c;
    cin>>a;
    string operation;
    while(a--)
    {
        cin>>operation;
        if(operation == "print")
        {
            cin>>b>>c;
            cout.write(text + b, c - b + 1);
            cout<<endl;
        }
        else if(operation == "reverse")
        {
            cin>>b>>c;
            reverse(text + b, text + c + 1);
        }
        else
        {
            cin>>b>>c;
            for(int i = b; i <= c; i++)
                cin>>text[i];
        }
    }
    return 0;
}


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


int main(){
    int n; cin >>n;
    vector<pair<int,int>> ba(n);
    for(int i=0;i<n;i++){
        cin >> ba[i].second >> ba[i].first ;
    }
    sort(ba.begin(),ba.end());
    int wt=0; //working time
    for(int i=0;i<n+1;i++){
        //cout<< "i=" << i << endl;
        if(i==n){
            cout << "Yes" << endl; break;
        }
        if(wt+ba[i].second <= ba[i].first){
            //cout << "wt=" << wt << " ba[i]=" <<ba[i].first<<" "<<ba[i].second<<endl;
            wt += ba[i].second;
            //cout << "wtはこれになった→"<<wt<<endl;
        }else{
            cout << "No" << endl;
            break;
        }
    }
    //cout << wt << endl;

}




Measured memory_bytes: 1920
import sys
import heapq
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
p = []
for i in range(N):
  x, y = map(int, input().split())
  p.append((x, y, i))

e = dd(list)
ps = sorted(p, key = lambda x: (x[1], x[0]))
for i in range(N - 1):
  u = ps[i][2]
  v = ps[i + 1][2]
  d = min(abs(p[u][0] - p[v][0]), abs(p[u][1] - p[v][1]))
  e[u].append((v, d))
  e[v].append((u, d))
ps.sort(key = lambda x: (x[0], x[1]))
for i in range(N - 1):
  u = ps[i][2]
  v = ps[i + 1][2]
  d = min(abs(p[u][0] - p[v][0]), abs(p[u][1] - p[v][1]))
  e[u].append((v, d))
  e[v].append((u, d))
#print(e)

class prim:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def MSTcost(self):
    h = []
    visited = [0] * (self.n + 1)
    ks = list(self.e.keys())
    b = pow(10, 10)
    for edge in self.e[ks[0]]:
      heapq.heappush(h, edge[1] * b + edge[0])
    res = 0
    visited[ks[0]] = 1
    while len(h):
      p = heapq.heappop(h)
      p0 = p // b
      p1 = p % b
      if visited[p1]: continue
      visited[p1] = 1
      for q in self.e[p1]:
        if visited[q[0]]:
          continue
        heapq.heappush(h, q[1] * b + q[0])
      res += p0
    return res

pri = prim(N, e)
print(pri.MSTcost())

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

using namespace std;
 
int main() {
    int a,b;
    cin>>a>>b;
    if(a>= 13) cout<<b;
    else if(a>=6) cout<<b/2;
    else cout<<"0";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#include<queue>
#define mod 998244353
#define pb push_back
#define ll long long
using namespace std;
int red[1145140],num[1145140];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		num[i]=1;
	}
	red[1]=1;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		if(red[a]==1)red[b]=1;
		num[a]--;
		num[b]++;
		if(num[a]==0)red[a]=0;
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(red[i]==1)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<int>> mat;

ll mod=pow(10,9)+7;
int main(){
    int N;cin>>N;
    vec A(300010);
    vec x(100,0);
    for(int i=0;i<N;i++){
        cin>>A[i];
        int j=0;
        while(A[i]>0){
            if(A[i]%2==1){
                x[j]++;
            }
            A[i]/=2;
            j++;
        }
    }
    ll ans=0;
    for(int k=100;k>=0;k--){
        ans=(ans*2)%mod;
        ans=(ans+(x[k]*(N-x[k]))%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
N = int(input())

lst = []
cnt = 1
while True:
    lst.append(6**cnt)
    if N < lst[-1]:
        lst.pop()
        break
    else:
        cnt += 1
cnt = 1
while True:
    lst.append(9**cnt)
    if N < lst[-1]:
        lst.pop()
        break
    else:
        cnt += 1
lst.append(1)
lst.sort()
i = 0
DP = [100000]*100001
DP[0] = 0
for i in range(100001):
    for add in lst:
        if i+add <= N:
            DP[i+add] = min(DP[i+add],DP[i]+1)
print(DP[N])

Measured memory_bytes: 3828
object Main extends App {
  val Array(n, k) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  var ans = 0.0

  (1 to n).foreach { i =>
    if (i >= k) {
      ans += 1 / n.toDouble
    } else {
      var cnt = 0
      var sum = i
      while (sum < k) {
        cnt += 1
        sum *= 2
      }
      ans += Math.pow(0.5, cnt) / n.toDouble
    }
  }

  println(ans)
}

Measured memory_bytes: 25424
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
int h,w;
void solve(){
  int length2 = h*h + w*w;
  int minHeight = 150;
  int minWidth;
  int minLength = 255000;
  for(int height = 1; height <= 150 ; height++){
    for(int width = height + 1; width <= 150 ; width++){
      int l = height * height + width * width;
      if(length2 < l || (length2 == l && h < height)){
        if( minLength > l || (minLength == l && minHeight > height) ){
          minHeight = height;
          minWidth = width;
          minLength = l;
        }
      }
    }
  }

  cout << minHeight << " " << minWidth << endl;
}

int main(){
  while(true){
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3088
#include<stdio.h>

int main(){
	int ah;
	int am;
	int as;
	int bh;
	int bm;
	int bs;
	int h;
	int hh;
	int m;
	int mm;
	int mmm;
	int s;
	int i;
	for(i = 2; i >= 0; i--){
		scanf("%d %d %d", &ah, &am, &as);
		scanf("%d %d %d", &bh, &bm, &bs);
		h = bh - ah;
		if(am > bm){
			hh = h - 1;
			m = bm + 60 - am;
			if(as > bs){
				mm = m - 1;
				s = bs + 60 - as;
				printf("%d %d %d\n", hh, mm, s);
			}else{
				s = bs - as;
				printf("%d %d %d\n", hh, m, s);
			}
		}else{
			m = bm - am;
			if(as > bs){
				mm = m - 1;
				s = bs + 60 - as;
				if(mm < 0){
					hh = h - 1;
					mmm = 59;
					printf("%d %d %d\n", hh, mmm, s);
				}else{
					printf("%d %d %d\n", h, mm, s);
				}
			}else{
				s = bs - as;
				printf("%d %d %d\n", h, m, s);
			}
		}
	}
	return 0;

}

Measured memory_bytes: 600
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Tsundoku
	var N, M, K int
	fmt.Scan(&N, &M, &K)

	sc.Split(bufio.ScanWords)
	var temp int

	A := make([]int, N+1)
	sumA := make([]int, N+1)
	temp = 0
	for i := 1; i <= N; i++ {
		A[i] = nextInt()
		temp += A[i]
		sumA[i] = temp
	}

	B := make([]int, M+1)
	sumB := make([]int, M+1)
	temp = 0
	for i := 1; i <= M; i++ {
		B[i] = nextInt()
		temp += B[i]
		sumB[i] = temp
	}

	var J int = M
	var max int = 0
	for i := 0; i <= N; i++ {
		if sumA[i] > K {
			break
		}
		for j := J; 0 <= j; j-- {
			if sumA[i]+sumB[j] <= K {
				if J > j {
					J = j
				}

				if max < i+j {
					max = i + j
				}
				break
			} else {
				continue
			}
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 9596
// https://atcoder.jp/contests/arc094/tasks/arc094_c

#include "algorithm"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll N;
  cin >> N;
  VL as(N);
  VL bs(N);

  ll last_element = 1e18;  // a > b なる b で最小のもの。操作で最後に一致させる

  ll sum = 0;
  rep(i, N) {
    cin >> as[i] >> bs[i];
    sum += as[i];

    if (as[i] > bs[i]) chmin(last_element, bs[i]);
  }

  if (as == bs) drop(0);

  ll a_sum = accumulate(as.begin(), as.end(), 0ll);
  ll res = a_sum - last_element;

  drop(res);
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using graph = vector<vector<int>>;

vector<bool> seen;

void dfs(const graph &tree,int pla,vector<int> &coun){
	seen.at(pla)=true;
	for(auto i : tree.at(pla)){
		if(seen.at(i)){
			continue;
		}
		else{
			coun.at(i)+=coun.at(pla);
			dfs(tree,i,coun);
		}
	}

	
}


int main(){
	int N,Q;
	cin >> N >> Q;
	graph tree(N,vector<int>(0));
	int a,b;
	for(int i=0;i<N-1;i++){
		cin >> a>> b;
		a--;
		b--;
		tree.at(a).push_back(b);
		tree.at(b).push_back(a);
	}
	
	vector <int> coun(N,0);
	int p,x;
	for(int i=0;i<Q;i++){
		cin >> p>>x;
		p--;
		coun.at(p)+=x;
	}
	seen.assign(N,false);
	dfs(tree,0,coun);
	
	for(int i=0;i<N;i++){
		cout<<coun.at(i)<<" ";
	}
	cout<<endl;
	
	return 0;

}




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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll R,G,B,N;
    string S;
    cin >> R>>G>>B>>N;

    ll tmp;
    ll ans = 0;
    REP(i, N / R+1)
    {
        REP(j,N/G+1){
            tmp = N - R * i - G * j;
            if(tmp>=0&&tmp%B==0){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(){
	cin>>a;
	cin>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end(),greater<char>());
	if(a<b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define NILL -1

struct Node{
  int p;
  int l;
  int r;
};
  
struct Node A[N];
int n,B[N];

  
  int rec(int x,int y){
    B[x] = y;
    if(A[x].r != NILL) rec(A[x].r,y);
    if(A[x].l != NILL) rec(A[x].l,y + 1);
  }
  

int main(){
  int i,j,d,v,c,l,r,n,op;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p = A[i].l = A[i].r = NILL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) A[v].l=c;
      else A[l].r = c;
      l=c;
      A[c].p = v;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].p == -1) r=i;
  }

  rec(r,0);

  for(i=0;i<n;i++){
   
    printf("node %d: parent = %d, depth = %d,",i,A[i].p,B[i]);
    if(A[i].p == -1) printf(" root,");
    else if(A[i].l == -1 ) printf(" leaf,");
    else printf(" internal node,");
    printf(" [");
    for(j=0,op=A[i].l;op != -1;j++,op = A[op].r){
      if(j != 0) printf(", ");
      printf("%d",op);
    }
    printf("]\n");  
  }

  return 0;
}



Measured memory_bytes: 6448
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

string s, t;

int main() {
	cin >> s >> t;
	REP(i, s.size()) {
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		t = t[t.size() - 1] + t;
		t.pop_back();
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X = int(read())
# なるべく 500
q, r = divmod(X, 500)
answer = 1000 * q + (r // 5) * 5
print(answer)


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

int main() {
  int n;
	cin >> n;
  int a[n], sum=0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		while (a[i] % 2 == 0) { a[i] /= 2; sum++; }
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

using pii = pair<int, int>;

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

    vector<int> c;
    c.push_back(-a[0]);
    for (int i = 1; i < N; i++)
    {
        auto iter = upper_bound(c.begin(), c.end(), -a[i]);
        if (iter == c.end())
        {
            c.push_back(-a[i]);
        }
        else
        {
            *iter = -a[i];
        }
    }

    int ans = c.size();
    cout << ans << endl;
    return 0;
}

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

struct ans {
  int ans[4];
};
vector<ans> ls;
int h, w;

int mp[505][505] = {0};

void solve();

int main() {
  int i, j;
  cin >> h >> w;
  for(i = 0; i < h; ++i)
    for(j = 0; j < w; ++j) cin >> mp[i][j];
  solve();
  cout << ls.size() << endl;
  for(i = 0; i < ls.size(); ++i) {
    for(j = 0; j < 4; ++j) {
      cout << ls[i].ans[j] + 1;
      if(j != 3) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

void solve() {
  int i, j;
  ans now;
  for(i = 0; i < h; ++i)
    for(j = 0; j < w; ++j)
      if(mp[i][j] % 2 != 0) {
        now.ans[0] = i;
        now.ans[1] = j;
        if(j != w - 1) {
          now.ans[2] = i;
          now.ans[3] = j + 1;
          ++mp[i][j + 1];
          ls.push_back(now);
        }
        else if(i != h - 1) {
          now.ans[2] = i + 1;
          now.ans[3] = j;
          ++mp[i + 1][j];
          ls.push_back(now);
        }
      }
}

Measured memory_bytes: 5232
from collections import deque
h,w=map(int,input().split())
l=[]
l.append('@'*(w+2))
for i in range(h):
    l.append('@'+input()+'@')
l.append('@'*(w+2))
q=deque()
p=[[-1 for i in j] for j in l]
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='#':
            q.append([i,j])
            p[i][j]=0
while len(q)>0:
    x,y=q.popleft()
    for i,j in [[1,0],[-1,0],[0,-1],[0,1]]:
        if l[x+i][y+j]=='.' and p[x+i][y+j]==-1:
            q.append([x+i,y+j])
            p[x+i][y+j]=p[x][y]+1
a=0
for i in p:
    for j in i:
        a=max(a,j)
print(a)
#print(*p,sep='\n')

Measured memory_bytes: 166824
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

struct edge{
	int to;
	long long int cost;
};

#define MAX_V 110000

vector<edge> E[MAX_V];
long long int d[MAX_V];

void func(int u, int pre, int dist){
	d[u] = dist;
	for(int i = 0; i < E[u].size(); i++){
		if(E[u][i].to != pre){
			func(E[u][i].to, u, dist + E[u][i].cost);
		}
	}
}

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N - 1; i++){
		int u, v, c;
		cin >> u >> v >> c;
		edge p;
		p.cost = c;
		p.to = v;
		E[u].push_back(p);
		p.to = u;
		E[v].push_back(p);
	}
	
	func(0, -1, 0);
	
	int index = 0;
	int dmax = 0;
	for(int i = 0; i < N; i++){
		if(d[i] > dmax){
			dmax = d[i];
			index = i;
		}
	}
	func(index, -1, 0);
	
	dmax = 0;
	for(int i = 0; i < N; i++){
		if(d[i] > dmax){
			dmax = d[i];
		}
	}
	
	cout << dmax << endl;
	
	return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

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

	if(a <= 8 && b <= 8){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}



    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;

long long three_point(long long x, long long one, long long two){
  
  if(x < one && x < two)
    return max(one,two)-x;
  
  if(x > one && x > two)
    return x-min(one,two);
  
  return min(abs(x-one)*2 + abs(x-two), abs(x-two)*2 + abs(x-one));

}

long long calc(long long x, long long tplus, long long tminus, long long splus, long long sminus){

  return min({
  three_point(x,tplus,splus),three_point(x,tplus,sminus),
  three_point(x,tminus,sminus),three_point(x,tminus,splus),
  three_point(x,splus,tplus),three_point(x,splus,tminus),
  three_point(x,sminus,tminus),three_point(x,sminus,tplus)
  });

}

int main(){

  int A, B, Q; cin >> A >> B >> Q;
  vector<long long> s(A+2);
  vector<long long> t(B+2);
  for(int i=1; i<=A; i++) cin >> s.at(i);
  for(int i=1; i<=B; i++) cin >> t.at(i);

  s.at(0) = -INF; t.at(0) = -INF; s.at(A+1) = INF; t.at(B+1) = INF;
  
  for(int i=0; i<Q; i++){
    long long x; cin >> x;
    
    auto it_s = lower_bound(s.begin(), s.end(), x);
    auto it_t = lower_bound(t.begin(), t.end(), x);
    
    cout << calc(x, *it_t, *(it_t-1), *it_s, *(it_s-1)) << endl;
  }
}

Measured memory_bytes: 2944
#include"bits/stdc++.h"
using namespace std;
void ok() {
	puts("YES");
	exit(0);
}
int main() {
	string s;
	cin >> s;
	string goal = "keyence";
	if (s == goal) {
		ok();
		return 0;
		 }
	for (int i = 0; i < s.size(); i++) {
		for (int j = i; j < s.size(); j++) {
			string t;
			if (i) {
				t += s.substr(0, i);
			}
			if (j != s.size() - 1) {
				t += s.substr(j + 1, s.size() - j-1);
			}
			if (t == goal) {
				ok();
			}
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

map<ll, int> mapp;

void factorise(ll n)  
{   
    while(!(n & 1))  
    {  
        mapp[2]++;
        n /= 2;  
    }
    for(ll i = 3; i <= sqrtl(n); i += 2)  
    { 
        while(!(n % i))  
        {  
           	mapp[i]++;  
            n /= i;  
        }  
    }
    if(n > 2)  
    	mapp[n]++;  
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, ans = 0; cin >> n;
	vector<ll> pre(101);
	for(ll i = 1; i < 101; i++) pre[i] = pre[i - 1] + i;
	factorise(n);
	for(auto x : mapp)
	{
		int lb = (lower_bound(pre.begin(), pre.end(), x.second) - pre.begin());
		ans += lb - (pre[lb] > x.second);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
 
int main() {
    int n,x;
    cin >> n >> x;
    vector <ll>  m(n);
    rep(i,0,n) {
        cin >> m[i];
        x -= m[i];
    }
    sort(m.begin(),m.end());
    cout << x / m[0] + n << endl;

}

Measured memory_bytes: 3156
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i+1, N):
        count = 0
        for k in range(j + 1, N):
            
            if L[i] + L[j]  > L[k]  and L[i] < L[j] and L[j] < L[k]:
                count += 1
                #print(i, j, k, count, ans)
            elif L[i] + L[j]  < L[k] :
                #print(L[i], L[j], L[k])
                break
        ans = ans + count
            #print(ans)
print(ans)


Measured memory_bytes: 67956
import sys
N, K = [int(x) for x in input().split()]

p = 10 ** 9 + 7
a = 10 ** 100 % p

ans = 0
for i in range(K, N + 2):
    l = (i * (i - 1) // 2 + i * a) % p
    r = (i * (2 * N - i + 1) // 2 + i * a) % p
    ans += (r - l + 1) % p
    ans %= p
print(ans)

Measured memory_bytes: 9220
n,k=map(int,input().split())
s=input()
num=[0]
c=1
for i in range(1,n):

    if s[i]==s[i-1]:
        c+=1
    else:
        num.append(c)
        c=1
num.append(c)
num.append(0)
#print(num)

ans=0
#print(num)
if s[0]=="0":
    if len(num)-2*k+1<=0:
        ans=sum(num)
    else:
        asum=sum(num[0:2*k+1])
        ans=asum
        #print(asum)
        for i in range(2,len(num)-2*k,2):
            #print(asum,num[i+2*k],num[i+2*k-1],num[i-1],num[i-2])
            asum=asum+num[i+2*k]+num[i+2*k-1]-num[i-1]-num[i-2]
            ans=max(ans,asum)
if s[0]=="1":
    if len(num)-2*k+2<=0:
        ans=sum(num)
    else:
        asum=sum(num[1:2*k+2])
        ans=asum
        for i in range(3,len(num)-2*k,2):
            #print(asum,num[i+2*k],num[i+2*k-1],num[i-1],num[i-2])
            asum=asum+num[i+2*k]+num[i+2*k-1]-num[i-1]-num[i-2]
            ans=max(ans,asum)
print(ans)


Measured memory_bytes: 45936
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int a[101][101], b[101][101];
    long long c[101][101], s;
    int i, j, k;
    int n, m, l;
 
    scanf("%d%d%d", &n, &m, &l);
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
    }
    for (i = 0; i < m; i++) {
        for (j = 0; j < l; j++) scanf("%d", &b[i][j]);
    }
 
    for (i = 0; i < n; i++) {
        for (j = 0; j < l; j++) {
            s = 0;
            for (k = 0; k < m; k++) {
                s += a[i][k] * b[k][j];
            }
            c[i][j] = s;
        }
    }
 
    for (i = 0; i < n; i++) {
        printf("%lld", c[i][0]);
        for (j = 1; j < l; j++) printf(" %lld", c[i][j]);
        putchar('\n');
    }
    return 0;
}


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

int main()
{
	int N;
	scanf("%d", &N);

	char ans[100000][7] = {};
	printf("0\n");
	fflush(stdout);
	scanf("%s", ans[0]);
	if (ans[0][0] == 'V') return 0;
	printf("%d\n", N - 1);
	fflush(stdout);
	scanf("%s", ans[N-1]);
	if (ans[N-1][0] == 'V') return 0;
	
	int i, l = 0, u = N - 1;
	while (1) {
		i = (l + u) / 2;
		printf("%d\n", i);
		fflush(stdout);
		scanf("%s", ans[i]);
		if (ans[i][0] == 'V') return 0;
		else if (ans[i][0] == ans[l][0] && (i - l) % 2 == 1) u = i;
		else if (ans[i][0] != ans[l][0] && (i - l) % 2 == 0) u = i;
		else l = i;
	}
}

Measured memory_bytes: 1492
#include<stdio.h>
int main(void){
	int n;
	int i;
	int stone,person;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d %d",&stone,&person);
		while(1){
			stone -= person;
			if(stone <= 0){
				break;
			}
		}
		printf("%d\n",stone + person);
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		String S = stdIn.next();
		int ans = 0;
		for(int i = 0; i < N - 2; i++){
			if(S.substring(i,i+3).equals("ABC")){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
}


Measured memory_bytes: 35324
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int c[200005], p2[200005], p4[200005];
int func(int l){
    if(l == 0) return 0;
    return l*1ll*p2[l-1]%mod;
}
int main(){
    int n;
    scanf("%d", &n);
    p2[0] = p4[0] = 1;
    for(int i=1;i<=n;i++){
        scanf("%d", &c[i]);
        p2[i] = p2[i-1]*2%mod;
        p4[i] = p4[i-1]*1ll*4%mod;
    }   
    sort(c+1, c+1+n);
    int ans = 0;
    for(int i=1;i<=n;i++){
        int l = i-1, r = n-i;
        int res = p4[l]*1ll*p2[r+1]%mod*(func(r) + p2[r])%mod*c[i]%mod;
        ans = (ans + res)%mod;
    }
    printf("%d\n", ans);
}

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

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

using vi = vector<int>;

map<vi, int> mp; // mp[ある盤面]: その盤面に到るまでの手数

void bfs(vi origin) {
  // キューの初期化
  queue<vi> que;
  que.push(origin);
  // データの初期化
  mp[origin] = 0;

  while (que.size()) {
    // 軸を取り出す
    vi axis = que.front(); que.pop();

    // 0の場所を求める
    int zeroPos = 0;
    for (int i = 0; i< axis.size(); i++) {
      if (axis[i] == 0) zeroPos = i;
    }
    int y = zeroPos / 4, x = zeroPos % 4;
    int pos = y * 4 + x;

    // 軸から行ける場所を列挙
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;
      int npos = ny * 4 + nx;
      vi next = axis;
      swap(next[npos], next[pos]);
      if (mp.count(next)) continue;
      // 行けるならキューとデータを更新する
      mp[next] = mp[axis] + 1;
      que.push(next);
    }
  }
}


signed main() {
  // 前処理
  vector<int> origin(8);
  iota(origin.begin(), origin.end(), 0);
  bfs(origin);

  string s;
  while (getline(cin, s)) {
    vi v;
    for (int i = 0; i < s.size(); i+=2) {
      v.push_back(s[i] - '0');
    }
    // 前処理の結果を出力するだけ
    cout << mp[v] << endl;
  }

  return 0;
}


Measured memory_bytes: 5648
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

int main() {
    int n;
    cin >> n;
    long sum = 0;
    vector<int> v;
    REP(i,n) {
        int j;
        cin >> j;
        sum += j;
        v.push_back(j);
    }
    sort(v.begin(), v.end());
    cout << v[0] << " " << v[v.size()-1] << " " << sum << endl;
    return 0;
}

Measured memory_bytes: 1328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(std::vector<std::string> s){
    rep(i,3){
        cout<<(char)(s[i][0]+'A'-'a');
   }
   cout<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<std::string> s(3);
    for(int i = 0 ; i < 3 ; i++){
        std::cin >> s[i];
    }
    solve(std::move(s));
    return 0;
}


Measured memory_bytes: 256
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;

use std::cmp::*;

fn main() {
    input! {
        n: usize,
        b: [u64;n-1],
    }

    let mut a = vec![0_u64; n];

    a[0] = b[0];
    a[n - 1] = b[n - 2];

    for i in 1..n - 1 {
        a[i] = min(b[i], b[i - 1]);
    }

    println!("{}", a.iter().fold(0, |sum, x| sum + x));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

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

using namespace std;
typedef		int_least64_t		LL;

int main()
{
	int		n;
	LL		min = 1000000 + 1;
	LL		max = -1 * min;
	LL		sum = 0;
	LL		t;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> t;
		if (t < min)		min = t;
		if (t > max)		max = t;
		sum += t;
	}

	cout << min << " " << max << " " << sum << "\n";

	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int MAX = 2000005;
const ll mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
 
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


int main(){
    ll N, M, K; cin >> N >> M >> K;
    COMinit();

    ll ans = 0;
    for(int d=1; d<=N-1; d++){
        ans += d*(N-d)%mod*M%mod*M%mod*COM(N*M-2, K-2)%mod;
        ans %= mod;
    }

    for(int d=1; d<=M-1; d++){
        ans += d*(M-d)%mod*N%mod*N%mod*COM(N*M-2, K-2)%mod;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 47104
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int height[1500001]={0};
int width[1500001]={0};

int main(){
    int h[1501],w[1501];
    int N,M,result=0;

    while(cin >> N >> M && N){
	for(int i=0; i<1500001; ++i){
	    height[i]=0;width[i]=0;
	}
	for(int i=0; i<N; ++i) cin >> h[i];
	for(int i=0; i<M; ++i) cin >> w[i];
	int temp=0;
	for(int i=0; i<N; ++i){
	    temp = h[i];
	    height[temp]++;
	    for(int j=i+1; j<N; ++j){
		temp += h[j];
		height[temp]++;
	    }
	}
	temp =0;
	for(int i=0; i<M; ++i){
	    temp = w[i];
	    width[temp]++;
	    for(int j=i+1; j<M; ++j){
		temp += w[j];
		width[temp]++;
	    }
	}
	int count =0;
	for(int i=1; i<1500001; ++i){
	    count += height[i]*width[i];
//	    if(height[i]!=0 || width[i]!=0)
//		cout <<i <<":"<< height[i] << ":" << width[i] << endl;
	}
	
	cout << count << endl;
	//     height=0;
	//     for(int j=i; j<1500; ++j){
	// 	height += h[j];
	// 	for(int k=0; k<1500; ++k){
	// 	    width=0;
	// 	    for(int l=0; l<1500; ++l){
	// 		width += w[l];
	// 		if(height==width)
	// 		    result++;
	// 		else if(height < width)
	// 		    break;
	// 	    }
	// 	}
	//     }
	// }
	// cout << result << endl;
	// height=0;width=0;result=0;
	// for(int i=0; i<N; ++i) h[i]=0;
	// for(int i=0; i<M; ++i) w[i]=0;

    }
    return 0;
}

Measured memory_bytes: 12892
void main() {
    dchar[] n = readln.chomp.to!(dchar[]);
    dchar[] m = n.dup;
    reverse(m);
    writeln(n == m ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main(){
  string C;
  C="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int n;
  char S[10000];
  cin >> n >> S;
  int a=strlen(S);
  int i,j;
  for(i=0;i<a;i++){
    for(j=0;j<26;j++){
      if(S[i]==C[j]){
        cout << C[j+n];
        break;
      }else if(S[i]!=C[j]){
        continue;
      }
    }
  }
  return(0);
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()

  println(abc159b(s))
}

private fun abc159b(s: String): String {
  val n = s.length
  var ok = true
  if (s.reversed() != s) {
    ok = false
  }
  val subA = s.substring(0, (n - 1) / 2)
  if (subA.reversed() != subA) {
    ok = false
  }
  val subB = s.substring((n + 1) / 2, n)
  if (subB.reversed() != subB) {
    ok = false
  }

  if (ok) {
    return "Yes"
  }
  return "No"
}

Measured memory_bytes: 31392
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)
#define COUT(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================
// Template End =========================

constexpr int MOD=1e9+7;

int main(void){
  int N; cin>>N;
  vec<int> a(N); cin>>a; SORT(a);
  int ans=INT_MAX;
  for(int i=a[0]; i<=a[N-1]; ++i){
    int tmp=0;
    ran(j,a){
      tmp+=(i-j)*(i-j);
    }
    ans=min(ans,tmp);
  }
  COUT(ans);
}












Measured memory_bytes: 256