akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){
    long long N, K;
    cin >> N >> K;
    vector<long long> a(N), cumsum(N + 1, 0);
    for(int i = 0; i < N; i++){
        cin >> a[i];
        cumsum[i + 1] = cumsum[i] + a[i];
    }
    vector<long long> s(N * (N + 1) / 2);
    int count = 0;
    for(int l = 0; l < N; l++){
        for(int r = l; r < N; r++){
            s[count++] = cumsum[r + 1] - cumsum[l];
        }
    }
    long long ans = 0;
    for(int p = 50; p >= 0; p--){
        long long m = (1LL << p);
        int c = 0;
        for(auto itr = s.begin(); itr != s.end(); itr++){
            if(((*itr) & m) != 0){
                // cout << *itr << " & " << m << " != 0" << endl;
                c++;
            }else{
                // cout << *itr << " & " << m << " == 0" << endl;
            }
        }
        if(c >= K){
            // cout << p << " gotcha!" << endl;
            ans |= m;
            for(auto itr = s.begin(); itr != s.end(); itr++){
                if(((*itr) & m) == 0) *itr = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

ll solve(ll N, ll X, vector<ll> &A);
int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N, X;
  cin >> N >> X;
  vector<ll> A;
  rep (i, N) {
    ll v0;
    cin >> v0;
    A.push_back(v0);
  }

  ll ans = solve(N, X, A);
  cout << ans << "\n";
}
ll solve(ll N, ll X, vector<ll> &A) {
  sort(all(A));
  ll s = 0;
  rep (i, N) {
    s += A[i];
    if (s > X) return i;
  }
  if (s == X) return N;
  return N - 1;
}


Measured memory_bytes: 256
import bisect

N= int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
c_num = len(c_list)

a_list.sort()
c_list.sort()

ans = 0
for b in b_list:
    a_point = bisect.bisect_left(a_list,b)
    c_point = bisect.bisect(c_list,b)
    
    ans+= a_point*(c_num-c_point)
print(ans)


Measured memory_bytes: 23360
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int x, n;
  vector<int> a, b;
  
  cin >> x >> n;
  
  for (int i = 0; i < n; i++) {
	int v;
    cin >> v;
    a.push_back(v);
  }
  
  if (a.end() == find(a.begin(), a.end(), x)) {
    cout << x << endl;
    return 0;
  }
  
  for (int d = 1; d < 100; d++) {
    if (a.end() == find(a.begin(), a.end(), x - d)) {
      cout << x - d << endl;
      return 0;
    } else if (a.end() == find(a.begin(), a.end(), x + d)) {
      cout << x + d << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
#include <cctype>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main () {
	int n, q;
	int current = 0;
	queue<pair<string, int> > que;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		string name;
		int p;
		cin >> name >> p;
		que.push(make_pair(name, p));
	}
	while (!que.empty()) {
		pair<string, int> proc = que.front();
		que.pop();
		int use = min(q, proc.second);
		current += use;
		if (use == proc.second) {
			cout << proc.first << ' ' << current << endl;
		}
		else {
			proc.second -= use;
			que.push(proc);
		}
	}
	return 0;
}

Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<vector<int> >a(n);
  double ans=0;
  for(int i=0;i<n;i++)
  {
    int x,y;
    cin>>x>>y;
    a[i].resize(2);
    a[i][0]=x;
    a[i][1]=y;
  }
  for(int i=0;i<n-1;i++)
  {
    for(int j=i;j<n;j++)
    {
      ans+=((double)sqrt(pow(a[i][0]-a[j][0],2)+pow(a[i][1]-a[j][1],2)));
    }
  }
  cout<<fixed<<setprecision(10);
  cout<<ans*2/(n)<<endl;
   return 0;

   }


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,n,s;
	while ( scanf("%d%d%d",&a,&b,&n) != EOF ) {
		s=0;
		a %= b;
		while (n--) {
			a *= 10;
			s += (a/b)%10;
			a %= b;
		}
		printf("%d\n", s);
	}
	return 0;
}

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

int main() {
    string ABCD;
    cin >> ABCD;

    vector<int> vec(4);
    for (int i=0; i<4;i++) {
        vec.at(i) = ABCD.at(i)-'0';
    }

    vector<char> op(3);
    if (vec.at(0)+vec.at(1)+vec.at(2)+vec.at(3)==7) {
        op={'+','+','+'};
    }
    else if (vec.at(0)+vec.at(1)+vec.at(2)-vec.at(3)==7) {
        op={'+','+','-'};
    }
    else if (vec.at(0)+vec.at(1)-vec.at(2)+vec.at(3)==7) {
        op={'+','-','+'};
    }
    else if (vec.at(0)+vec.at(1)-vec.at(2)-vec.at(3)==7) {
        op={'+','-','-'};
    }
    else if (vec.at(0)-vec.at(1)+vec.at(2)+vec.at(3)==7) {
        op={'-','+','+'};
    }
    else if (vec.at(0)-vec.at(1)+vec.at(2)-vec.at(3)==7) {
        op={'-','+','-'};
    }
    else if (vec.at(0)-vec.at(1)-vec.at(2)+vec.at(3)==7) {
        op={'-','-','+'};
    }
    else if (vec.at(0)-vec.at(1)-vec.at(2)-vec.at(3)==7) {
        op={'-','-','-'};
    }

    for (int i=0; i<3; i++) {
        cout << vec.at(i);
        cout << op.at(i);
    }
    cout << vec.at(3) << "=7" << endl;
}

Measured memory_bytes: 3600
import os
import sys
from fractions import gcd
from functools import reduce

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())


def ok(s):
    if reduce(gcd, s) != 1:
        return False
    ok = True
    m = sum(s)
    for a in s:
        # gcd(m-a,a) < gcd(m,a)
        ok &= gcd(m, a) > 1
    return ok


if N == 3:
    ans = {2, 3, 25}
elif N <= 10001:
    ans = {2, 3, 10, 9}
    # 合計が 6 の倍数なので 6 の倍数を足しても条件を満たす
    c = 6
    while c < 30000 and len(ans) < N:
        ans |= {c}
        c += 6
    # 4-5003 まで

    c = 12
    while c + 4 < 30000 and len(ans) < N:
        ans |= {c + 2, c + 4}
        ans -= {c}
        c += 6
    # 10001 まで
else:
    # 2か3で割り切れるやつ全部
    ans = set()
    for i in range(2, 30001):
        if i % 2 == 0 or i % 3 == 0:
            ans.add(i)
    # 6の倍数を引いても条件を満たす
    c = 6
    while c < 30000 and len(ans) > N:
        ans -= {c}
        c += 6
    # 20000-15001までOK

    # 2 mod 6 のやつと 4 mod 6 のやつを引いて 6 の倍数を足す
    c = 4
    while c + 4 < 30000 and len(ans) > N:
        ans -= {c, c + 4}
        ans |= {c + 2}
        c += 6
    # 10002 まで

print(*ans)


Measured memory_bytes: 7276
s = input()
n = len(s)
kisu = ["R", "U", "D"]
gusu = ["L", "U", "D"]
for i in range(n):
    if i % 2 == 0:
        if s[i] in kisu:
            continue
    else:
        if s[i] in gusu:
            continue
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long b = 1;
  while (2 * b <= n) b*= 2;
  cout << 2 * b - 1 << endl;
}


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

#define FOR(s, i, n) for(int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int k, a, b;
	cin>>k>>a>>b;
	FOR(a, i, <=b){
		if(i%k==0){
			puts("OK");
			return 0;
		}
	}
	puts("NG");
	return 0;
}

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

int main(int argc, char const *argv[]) {
    std::string s1,s2,s3;
    std::cin >> s1 >> s2 >> s3;
    std::string t1{s1.front()};
    std::string t2{s2.front()};
    std::string t3{s3.front()};
    transform (t1.begin (), t1.end (), t1.begin (), toupper);
    transform (t2.begin (), t2.end (), t2.begin (), toupper);
    transform (t3.begin (), t3.end (), t3.begin (), toupper);
    std::cout << t1+t2+t3 << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

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

      char ca = "a".charAt(0);
      char cz = "z".charAt(0);
      int[] count = new int[26];

      br.lines()
        .parallel()
        .filter(s -> s != null && !s.isEmpty())
        .map(String::toLowerCase)
        .map(s -> IntStream.range(0,s.length())
          .mapToObj(i -> s.charAt(i))
          .filter(c -> !(ca > c  || c > cz))
          .mapToInt(c -> count[c -ca] += 1) 
          .toArray() )
        .toArray();
      
      IntStream.range(0, count.length)
        .forEach(i -> System.out.println(Character.valueOf((char)(ca + (char)i)).toString() + " : " + count[i]));
    }
  }
}


Measured memory_bytes: 32124
package main

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

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

func solve(a int64, b int64, c int64, d int64) int64 {
	if c < a {
		a, c = c, a
	}
	if d < b {
		b, d = d, b
	}
	ret := b - c
	if ret < 0 {
		ret = 0
	}
	return ret
}

func main() {
	defer out.Flush()

	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()
	res := solve(a, b, c, d)
	fmt.Fprintln(out, res)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 1772
# nCk(mod p)の計算
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9+7
MAX = 10**6+1

 # a!のテーブルfact
fact = [0] * MAX
# (a!)^-1のテーブルfinv
finv = [0] * MAX

def comb_init():
    # a!と(a!)^-1のテーブルを作る
    # 累積積のイメージ
    fact[0] = fact[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fact[i] = i * fact[i-1] % MOD
        finv[i] = pow(i, MOD-2, MOD) * finv[i-1] % MOD

def comb(n, r):
    return fact[n] * (finv[n-r] * finv[r] % MOD) % MOD    

n = (X+Y)//3
r = X-n
if not 0 <= r <= n:
    print(0)
    exit()

if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    comb_init()
    print(comb(num, p))

Measured memory_bytes: 80860
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.print((a * b) + " " + (a + a + b + b));
		System.out.println("");
		sc.close();
	}
}


Measured memory_bytes: 26196
N,A,B=[int(str1) for str1 in input().split()]
#print(N,A,B)
sums=0

def digits_sum(digits,len):
    sum=0
    for i in range(len):
        sum+=int(digits[i])
    return sum


for i in range(N+1):
    digits=str(i)
    sum=digits_sum(digits,len(digits))
    if sum>=A and sum<=B:
        sums+=i
    else:
        pass

print(sums)

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

int main()
{
    int n, x;
    while (cin >> n >> x)
    {
        int count = 0;
        if (x == 0 && n == 0)
            break;
        int a, b, c;
        for (a = 1; a<n - 1; a++) {
            for (b = a + 1; b<n; b++) {
                for (c = b + 1; c <= n; c++) {
                    if ((a + b + c) == x&&a!=b&&b!=c&&c!=a)
                        count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;

}

Measured memory_bytes: 1164
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   long long N;
   cin >> N;
   string ans;
   while(N!=0){
      ans += (N-1)%26+'a';
      N-=1;
      N/=26;      
   }
   reverse(ans.begin(),ans.end());
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3628
from collections import deque
from collections import defaultdict

def main():
    N, X, Y = map(int, input().split())
    graph = [[] for _ in range(N)]
    graph[X-1].append(Y-1)
    graph[Y-1].append(X-1)
    for i in range(N-1):
        graph[i].append(i+1)
        graph[i+1].append(i)

    dist_freq = defaultdict(int)
    for start in range(N):
        d = deque([start])
        distance = [-1] * N
        distance[start] = 0
        while d:
            current_node = d.popleft()
            for next_node in graph[current_node]:
                if distance[next_node] == -1:
                    distance[next_node] = distance[current_node] + 1
                    d.append(next_node)
        for v in distance:
            if v != 0:
                dist_freq[v] += 1
    for k in range(1, N):
        print(dist_freq[k] // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76232
#include "bits/stdc++.h"
#include <numeric>

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n;
  cin >> n;
  while(n) {
    if (n%10==7) {cout << "Yes" << endl; return;}
    n/=10;
  }
  cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i=1;i<n;i++)
		if (s[i]!=s[n-i]){
			puts("-1");
			return 0;
		}
	if (s[1]=='0'||s[n]=='1'){
		puts("-1");
		return 0;
	}
	int last=n,now=1;
	for (int i=n-1;i;i--)
		if (s[i]=='1'){
			int k=last-i-1,p=now;
			while (k--){
				p++;
				printf("%d %d\n",now,p);
			}
			p++;
			printf("%d %d\n",now,p);
			last=i;now=p;
		}
}

Measured memory_bytes: 1536
//    https://youtu.be/8SbUC-UaAxE

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))

int main(){
    fast;
    ll t,n,m,i,j,k,temp,flag,ans=0;
    cin>>n>>m;
    vector<pair<ll,ll> >v(n);
    priority_queue<ll>pq;
    for(i=0;i<n;i++){
        cin>>v[i].ff>>v[i].ss;
    }
    sort(all(v));
    for(i=1,j=0;i<=m;i++){
        for(;v[j].ff==i;j++){
            pq.push(v[j].ss);
        }
        if(pq.size()){
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2936
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,m,d;
string str;
char c[505][505];
int main()
{
	n=read();m=read();d=read();
	str="RYGB";
	for(int i=0;i<=n-1;i++,putchar('\n'))
		for(int j=0;j<=m-1;j++)
		{
			int x=i+j+m;
			int y=i-j+m;
			putchar(str[((x/d)&1)*2+((y/d)&1)]);
		}
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	ll n, m, ans = 0;
	cin >> n >> m;

	ans = min(n, m / 2);
	m -= ans * 2;
	ans += m / 4;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A = 0;
  int B = 0;
  int C = 0;
  int D = 0;
  int N;
  cin >> N;
  vector<string> E(N);
  for(int a = 0;a < N;a++){
    cin >> E[a];
    if(E[a] == "AC")A++;
    if(E[a] == "WA")B++;
    if(E[a] == "TLE")C++;
    if(E[a] == "RE")D++;
  }
  cout <<"AC x "<< A << endl;
  cout <<"WA x "<< B << endl;
  cout <<"TLE x "<< C << endl;
  cout <<"RE x "<< D << endl;
  
}

Measured memory_bytes: 6424
N = gets.to_i
S = gets.chomp
SI = S.split('').map{|c| c == '(' ? 1 : -1}

head = 0
tail = 0
depth = 0
SI.each do |i|
    depth += i
    if depth < 0
        head += 1
        depth += 1
    end
end
if depth > 0
    tail += depth
else
    head -= depth
end

puts '('*head + S + ')'*tail

Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7; // change if needed

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 2e5 + 5;

Modint dp [MAX_N];
Modint cdp [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;

  string s;
  cin >> s;

  if (s[0] == 'B') {
    for (int i = 0; i < m; i++) {
      if (s[i] == 'R') s[i] = 'B';
      else s[i] = 'R';
    }
  }

  vector<int> blocks;
  for (int i = 0; i < m; i++) {
    if (s[i] == 'R') {
      if (i == 0 || s[i - 1] == 'B') {
        blocks.push_back(0);
      }
      blocks.back()++;
    }
  }

  if (s.back() == 'R') {
    blocks.pop_back();
  }

  if (blocks.empty()) {
    // special case
    // just count the # of assignments
    // such that the blue things are singletons
    Modint ans (1 + n); // the all-red case
    dp[1] = Modint(1);
    cdp[1] = Modint(1);
    for (int i = 2; i < n; i++) {
      dp[i] = cdp[i - 2];
      cdp[i] = cdp[i - 1] + dp[i];
      ans += Modint(n + 1 - i) * dp[i];
    }
    cout << ans << endl;
    return 0;
  }

  int ub = n;
  for (int block : blocks) {
    if (block % 2 == 1) {
      ub = min(ub, block + 1);
    }
  }

  ub = min(ub, blocks[0] + 1);
  if (ub % 2 == 1) {
    ub++;
  }

  // do some DP to count the # of ways
  // to split a circle into odd-length pieces
  // separated by singleton pieces
  // such that each segment has length <= lb

  if (n % 2 != 0) {
    cout << 0 << endl;
    return 0;
  }
  
  Modint ans (0);
  dp[1] = Modint(1);
  cdp[1] = Modint(1);
  if (n <= ub) {
    ans += Modint(n) * dp[1];
  }
  
  for (int i = 3; i <= n; i += 2) {
    dp[i] = cdp[i - 2] - cdp[max(0, i - ub - 2)];
    cdp[i] = cdp[i - 2] + dp[i];

    if (n + 1 - i <= ub) {
      ans += Modint(n + 1 - i) * dp[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3920
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

void solve(int x){
    if(x == 0) cout<<"Yes"<<endl;
    else       cout<<"No"<<endl;
}

int main(){
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);
    int count = 0;
    while(1){
        if(count == 0){
            C -= B;
            if(C <= 0){
                solve(0);
                break;
            }
            count = 1;
        }
        else{
            A -= D;
            if(A <= 0){
                solve(1);
                break;
            }
            count = 0;
        }
    }
}

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

int main(){
    string s;
    cin >> s;
    
    int ansb = 0, answ = 0;
    
    rep(i,s.size()){
        if((s[i]+i)%2)ansb++;
        else answ++;
    }
    
    cout << min(ansb, answ) << endl;
    
    return 0;
}

Measured memory_bytes: 512
import sys


def main():
    N = int(input())
    A_list = list(map(int, input().split()))

    ans = 'APPROVED'
    for i_A in A_list:
        if i_A % 2 == 1:
            continue

        if i_A % 3 != 0 and i_A % 5 != 0:
            ans = 'DENIED'

    print(ans)

    return


if __name__ == "__main__":
    main()
    sys.exit(0)

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

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


//naosu
long int gcd(long int a,long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


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


long int f(long int n,long int c,long int d){
  long int cnt=n/c+n/d-n/lcm(c,d);
  return n-cnt;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  long int a,b,c,d;
  scanf("%ld%ld%ld%ld",&a,&b,&c,&d);

  printf("%ld\n",f(b,c,d)-f(a-1,c,d));

  return 0;
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

int n;//頂点数
int parent[100010];//iの親parent[i]を格納する配列
int my_rank[100010];//iを根とする部分木の高さみたいな量?
void init(int n){
    for(int i=0;i<n;i++){
        parent[i]=i;
        my_rank[i]=0;
    }
}
int root(int x){
    if(parent[x]==x)return x;
    else return root(parent[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return ;
    if(my_rank[x]<my_rank[y])parent[x]=y;
    else{
        parent[y]=x;
        if(my_rank[x]==my_rank[y])my_rank[x]++;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}
struct edge {int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}

vector <edge> edges;
long long kruskal(){
    sort(edges.begin(),edges.end(),comp);
    init(n);
    long long res=0;
    REP(i,edges.size()){
        edge e=edges[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res += (long long)e.cost;
        }
    }
    return res;
}

int main(){
  cin>>n;
  
  int x,y;
  vector<pair<int,int>> xs,ys;
  REP(i,n){
    cin>>x>>y;
    xs.push_back(make_pair(x,i));
    ys.push_back(make_pair(y,i));
  }
  
  sort(xs.begin(),xs.end());
  sort(ys.begin(),ys.end());
  
  REP(i,n-1){
    edge e;
    e.u = xs[i].second;
    e.v = xs[i+1].second;
    e.cost = xs[i+1].first - xs[i].first;
    edges.push_back(e);
  }
  REP(i,n-1){
    edge e;
    e.u = ys[i].second;
    e.v = ys[i+1].second;
    e.cost = ys[i+1].first - ys[i].first;
    edges.push_back(e);
  }
  
  long long ans;
  ans = kruskal();
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	for (int k = 0; k < 2; k++) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				int b; cin >> b;
				a[i][j] += (k == 0 ? 1 : -1)*b;
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			a[i][j] = abs(a[i][j]);
		}
	}
	constexpr int base = 25000;
	vector<vector<bitset<2*base>>> dp(H + 1, vector<bitset<2*base>>(W + 1));
	dp[0][0][base] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			dp[i + 1][j] |= dp[i][j] << a[i][j];
			dp[i + 1][j] |= dp[i][j] >> a[i][j];
			dp[i][j + 1] |= dp[i][j] << a[i][j];
			dp[i][j + 1] |= dp[i][j] >> a[i][j];
		}
	}
	auto f = [&](auto b) {
		int ret = 1e9;
		for (int i = 0; i < base; i++) {
			if (b[base + i]) ret = min(ret, i);
		}
		for (int i = 0; i < base; i++) {
			if (b[base - i]) ret = min(ret, i);
		}
		return ret;
	};
	cout << min(f(dp[H - 1][W]), f(dp[H][W - 1])) << endl;
	return 0;
}


Measured memory_bytes: 40960
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    deque<char> q;
    for (char c : s) q.push_back(c);
    int ans = 0;
    while (sz(q) > 1) {
        char c1 = q.front();
        char c2 = q.back();
        if (c1 != c2) {
            if (c1 == 'x') {
                ans++;
                q.pop_front();
            } else if (c2 == 'x') {
                ans++;
                q.pop_back();
            } else {
                ans = -1;
                break;
            }
        } else {
            q.pop_front();
            q.pop_back();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> h(N+2);
    h.at(0) = 0; h.at(N+1) = 0;
    for(int i = 1; i <= N; i++) cin >> h.at(i);
    
    int ans = 0;
    char now = '<';
    for(int i = 1; i <= N; i++) {
        if(now=='<' && h.at(i)>h.at(i+1)) {
            ans += h.at(i);
            now = '>';
        }
        if(now=='>' && h.at(i)<h.at(i+1)) {
            ans -= h.at(i);
            now = '<';
        }
    }
    cout << ans << endl;
}


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

public class Main {
    static int m, n;
    static ArrayList<String> data;
    static int[][] memo;

    static int toInt(boolean[] bool) {
        int ret = 0;
        for (boolean b: bool) {
            ret *= 2;
            if (b) ret += 1;
        }
        return ret;
    }

    // used: trueの位置はすべて同じ値 isZero: usedのtrueの位置に対して、その値が0か1か
    static int calc(boolean[] used, boolean[] isZero, ArrayList<String> rest) {
        int key = toInt(used), key2 = toInt(isZero);

        if (memo[key][key2] != -1) return memo[key][key2];
        if (rest.size() == 0 || rest.size() == 1) return 0;

        int ans = 12;
        for (int i = 0; i < m; ++i) {
            if (used[i]) continue;

            ArrayList<String> zeros = new ArrayList<>();
            ArrayList<String> ones = new ArrayList<>();
            for (String str : rest) {
                if (str.charAt(i) == '0') zeros.add(str);
                else ones.add(str);
            }

            used[i] = true;

            boolean[] tmp = new boolean[m];
            System.arraycopy(isZero, 0, tmp,0, m);
            tmp[i] = true;
            boolean[] tmp2 = new boolean[m];
            System.arraycopy(isZero, 0, tmp2,0, m);
            tmp2[i] = false;

            ans = Math.min(ans, 1 + Math.max(calc(used, tmp, zeros), calc(used, tmp2, ones)));
            used[i] = false;
        }

        memo[key][key2] = ans;
        return ans;
    }

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

        while (true) {
            m = scanner.nextInt();
            n = scanner.nextInt();
            if (m == 0 && n == 0) break;

            data = new ArrayList<>();
            memo = new int[(1 << m)][(1 << m)];
            for (int i = 0; i < (1 << m); ++i) {
                for (int j = 0; j < (1 << m); ++j) {
                    memo[i][j] = -1;
                }
            }

            for (int i = 0; i < n; ++i) {
                data.add(scanner.next());
            }

            System.out.println(calc(new boolean[m], new boolean[m], data));
        }
    }
}


Measured memory_bytes: 366992
import itertools

s = ["M","A","R","C","H"]

p = list(itertools.combinations(s,3))

dict ={"M":0,"A":0,"R":0,"C":0,"H":0}
n = input()
n = int(n)
names = []
for i in range(n):
        names.append(input())
for i in range(n):
        if names[i][0] in s:
                dict[names[i][0]] += 1
total_sum = 0
for part in p:
        sum = 1
        for j in range(3):
                sum *= dict[part[j]]
        total_sum += sum
print(total_sum)


Measured memory_bytes: 9772
# from https://atcoder.jp/contests/abc129/submissions/5845940
mod=1000000007
s=input()
chk=ans=0

for i,j in enumerate(s):
    if j=='0': continue
    chk+=1
    rest=len(s)-i-1
    ans+=pow(2,chk-1,mod) * pow(3,rest,mod) % mod
    ans%=mod
ans+=pow(2,chk,mod)
print(ans%mod)

Measured memory_bytes: 39664
import bisect,collections,copy,heapq,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

s = S()
cnt = 0
max_reg = 0
for x in s:
    if 'A' in x or 'C' in x or 'G' in x or 'T' in x:
        cnt += 1
    else:
        max_reg = max(max_reg,cnt)
        cnt = 0
max_reg = max(max_reg,cnt)
print(max_reg)

Measured memory_bytes: 10000
#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 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 A,B,C; cin >> A >> B >> C;

    int k = max(A,max(B, C));
    int sum = 0;
    sum = (k - A) + (k - B) + (k - C);
    if(sum % 2 == 0) {cout << sum/2 << endl; return 0;}
    else {cout << (sum+1)/2 + 1 << endl; return 0;}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
  #include <set>
  #include <array>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <stack>
  #include <queue>
  #include <vector>
  #include <tuple>
  #include <string>
  #include <math.h>
  #include <time.h>
  #include <bitset>
  #include <stdio.h>
  #include <string.h>
  #include <iostream>
  #include <algorithm>
  #include <limits>
  #include <climits>
  #include <numeric>
  #include <functional>
  #include <iomanip>
  #include <cmath>

  #define lnd '\n'
  // #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
  #define from(i, n) for (ll i = 0; i < n; ++i)
  #define loop(i, n) for(ll i = 0; i < n; i++)
  #define REPN(i, n) for (ll i = 1; i <= n; ++i)
  #define ALL(s) (s).begin(), (s).end()
  #define rALL(s) (s).rbegin(), (s).rend()
  #define sz(s) (int)(s).size()
  #define mk make_pair
  #define pb push_back
  #define sqr(s) ((s) * (s))

  using namespace std;

  typedef long long ll;
  typedef long long int lli;
  typedef long double ld;
  typedef unsigned long long ull;
  typedef unsigned int ui;

  template <class T>
  T GCD (T a, T b) {
    if(a == 0) return b;
    return GCD(b%a, a);
  }

  template <class T>
  T LCM(T a, T b){
    return a*b/GCM(a,b);
  }

  template <class T>
  T modpow(T x, T p){
      T res = 1;
      while(p > 0){
          if(p&1) res *= x;
          x *= x;
          p /= 2;
      }
      return res;
  }

  template <class T>
  T modpow(T x, T p, ll mod){
      T res = 1;
      while(p > 0){
          if(p&1) res = (res*x)%mod;
          x = (x*x)%mod;
          p /= 2;
      }
      return res%mod;
  }

  template <class T>
  void print(T a[], ll n){
      for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
      cout << endl;
  }

  template<class T>
  void printc(T c){
      for(auto const& v: c) std::cout << v << ' ';
      cout << endl;
  }

  struct HASH{
    size_t operator()(const pair<long,long>&x)const{
      return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
    }
  };

  bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
      if(p1.first != p2.first) return p1.first < p2.first;
      else return p1.second < p2.second;
  }

  const int INF = std::numeric_limits<int>::max();
  const ll M_INF = std::numeric_limits<ll>::min();
  const ll LL_INF = std::numeric_limits<ll>::max();

  void solution();
  int main(){
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
      solution();
      return 0;
  }

  void solution(){
    ll x, y;
    cin >> x >> y;
    if(y < 2*x || y%2){
      cout << "No" << endl;
    }else{
      ll d = y - 2*x;
      if(d == 0){
        cout << "Yes" << endl;
      }else if(d%2 == 0 && d/2 <= x){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
  }    


Measured memory_bytes: 3100
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)*}
    };
}

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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        bn:[usize;n-1],
    }
    let mut ans = bn[0];
    for i in 1..n{
        if i == (n-1){
            ans += bn[i-1];
        } else {
            ans += min(bn[i-1],bn[i]);
        }
    }
    println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define pf push_front
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1000000007;
int ll_max=1e6;



int main() {
	// your code goes here
	IOS;
	ll n,m,i,j,d;
	
	
      ll x,y,t,b,c,k;
      ll a[5];
      rep(i,5){
            cin>>a[i];
            if(a[i]==0){
                  c=i+1;
            }
      }
      cout<<c;
      return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
P x[100000],y[100000];
signed main(){
	int a,ans=0;
	cin>>a;
	f(i,a){
		int b,c;
		cin>>b>>c;
		y[i].F=b+c,y[i].S=b-c;
	}
	sort(y,y+a);
	int z=-INF;
	f(i,a){
		if(y[i].S>=z){
			z=y[i].F;
			ans++;
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main(){
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	long long int x=max(a*c,a*d);
	long long int y=max(b*c,b*d);
	cout<<max(x,y)<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;
 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

#define N 200001
#define eps 1e-9

int n, k; 
int a[N];

bool can(double len)
{
	ll sum = 0;
	for(int i = 0; i < n; i++)
	{
		int x = floor((a[i] - 1) / len);
		sum += x;
	}
	return sum <= (ll)k;
}

int main()
{
	fastIO;

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

	double low = 1e-3, high = 1e9;
	while(low < high - 1e-5)
	{
		double mid = low + (high - low) / 2;
		if(can(mid)) high = mid;
		else low = mid;

		// cout << low << ' ' << high << endl;
	}
	int ans = ceil(high);
	cout << ans << endl;

	return 0;
}

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

bool bjudge(int h,int w,int sh,int sw){
  int a=h*h+w*w;
  int b=sh*sh+sw*sw;
  if(a>b){return true;}
  if(a==b && h>sh){return true;}
  return false;
}






int main(){
  while(1){

    
  int h,w;
  cin>>h>>w;
  if(h==0 && w==0){break;}
  int ah=1,aw=pow(h*h+w*w-1,1.0/2)+1;
  pair<int,int> mi;
  mi=make_pair(ah,aw);
  while(1){
    while(bjudge(ah,aw,h,w)){aw--;}
    aw+=1;
    if(ah>=aw){break;}
    if(bjudge(mi.first,mi.second,ah,aw)){mi=make_pair(ah,aw);}
    ah++;
  }

  cout<<mi.first<<" "<<mi.second<<endl;


  }
  
  return 0;
}



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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	a = (a == 1? 14 : a);
	b = (b == 1? 14 : b);
	if (a == b) {
		cout << "Draw" << endl;
	} else if (a > b) {
		cout << "Alice" << endl;
	} else {
		cout << "Bob" << endl;
	}
	return 0;
}




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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, d;

	cin >> n >> d;

	vector<vector<ll>> v(n, vector<ll>(d, 0));

	REP(i, n) {
		REP(j, d) {
			cin >> v[i][j];
		}
	}

	ll sum, now;
	ll ans = 0;

	REP(i, n) {
		FOR(j, i + 1, n) {
			sum = 0;

			REP(k, d) {
				sum += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
			}

			now = sqrt(sum);

			if (now * now == sum) {
				ans++;
			}
		}
	}

	cout << ans << endl;
}

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

int main(){
    int N,*t,*x,*y,i,nowx=0,nowy=0,tmpt,dis;
    cin >> N;
    t = new int[N];
    x = new int[N];
    y = new int[N];
    for(i=0;i<N;i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    tmpt = t[0];
    for(i=0;i<N;i++){
        tmpt -= abs(x[i] - nowx);
        dis = abs(y[i]-nowy);
        if(tmpt<dis){
            cout << "No" << endl;
            return 0;
        }else{
            if(tmpt%2!=dis%2){
                cout << "No" << endl;
                return 0;
            }
        }
        nowx = x[i];
        nowy = y[i];
        if(i!=N-1){
            tmpt = t[i+1] - t[i];
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408