akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
using namespace std;

int N, A, B, C, D;
string S;

bool canReach(int begin, int end) 
{
	for (int i = begin + 1; i <= end; i++)
	{
		if (S[i] == '#' && S[i + 1] == '#')
		{
			return false;
		}
	}

	return true;
}

int main() 
{
	cin >> N >> A>> B >> C >> D >> S;

	A = A - 1;
	B = B - 1;
	C = C - 1;
	D = D - 1;

	S = "#" + S + "#";

	if (canReach(A, C) == false || canReach(B, D) == false)
	{
		cout << "No" << endl;
		return 0;
	}

	if (C > D)
	{
		for (int i = B + 1; i <= D + 1; i++)
		{
			if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.')
			{
				cout << "Yes" << endl;
				return 0;
			}
		}

		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;
set<int> a;
map<int, int> memo;
ll dp(int x)
{
    if (memo.count(x))
    {
        return memo[x];
    }
    if (a.count(x) || x < 0)
    {
        return 0;
    }
    if (x == 0)
    {
        return 1;
    }
    ll fx_1 = dp(x - 1);
    ll fx_2 = dp(x - 2);
    ll res = (fx_1 + fx_2) % MOD;
    memo[x] = res;
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;

    rep(i, M)
    {
        int tmp;
        cin >> tmp;
        a.insert(tmp);
    }
    //f(x)=f(x-1)+f(x-2);
    ll ans = dp(N);
    cout << ans << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 11136
class BinaryTree
  attr_accessor :root

  class Node
    attr_accessor :parent, :left, :right, :key

    def initialize(key)
      @key = key
      @parent = nil
      @left = nil
      @right = nil
    end
  end

  def initialize
    @root = nil
  end

  def insert(key)
    n = Node.new(key)
    y = nil
    x = @root

    while x != nil
      y = x
      x = if n.key < x.key
            x.left
          else
            x.right
          end
    end
    n.parent = y

    if y == nil
      @root = n
    elsif n.key < y.key
      y.left = n
    else
      y.right = n
    end
  end

  def find(key)
    n = @root
    while n != nil
      return true if n.key == key
      n = if key < n.key
        n.left
      else
        n.right
      end
    end
    return false
  end

  def inorder(n)
    return unless n
    inorder(n.left)
    print " #{n.key}"
    inorder(n.right)
  end

  def preorder(n)
    return unless n
    print " #{n.key}"
    preorder(n.left)
    preorder(n.right)
  end

  def dump
    inorder(@root)
    print "\n"
    preorder(@root)
    print "\n"
  end
end

n = gets.to_i
bt = BinaryTree.new

n.times do |i|
  cmd, v = gets.split
  case cmd
  when "insert"
    bt.insert(v.to_i)
  when "find"
    puts bt.find(v.to_i) ? "yes" : "no"
  when "print"
    bt.dump
  end
end

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

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

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N,T;
  cin >> N >> T;
  int cnt =10000;
  int cnt2;
  int ans=10000;
  int c,t;
  for(int i=0;i<N;i++){
    cin >> c >> t;
    if(t<=T){
      cnt =t;
      ans=min(ans,c);
    }
  }
  if(cnt==10000){
    cout << "TLE" << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 1005;
const int MAX_X = 5005;
int N;

vector<int> edge[MAX_N];
int X[MAX_N];

int sumX[MAX_N];

int calcSumX(int pos) {
    int ret = X[pos];

    for(int i = 0; i < edge[pos].size(); i++) {
        calcSumX(edge[pos][i]);
        ret += X[edge[pos][i]];
    }

    return sumX[pos] = ret;
}

int dp[MAX_N];

int dp2[MAX_N][MAX_X];

void init(int n, int v)
{
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= v; j++) {
            dp2[i][j] = INF;
        }
    }
}

int solve(int pos) {
    
    for(int i = 0; i < edge[pos].size(); i++) {
        int next = edge[pos][i];
        if(solve(next) == INF) {
            return dp[pos] = INF;
        }
    }

    init(edge[pos].size(), X[pos]);
    dp2[0][0] = 0;

    for(int i = 0; i < edge[pos].size(); i++) {
        int next = edge[pos][i];
        for(int j = 0; j <= X[pos]; j++) {
            if(dp2[i][j] == INF) {
                continue;
            }
            //nextと同じ色で塗る場合
            if(j+X[next] <= X[pos]) {
                // if(pos == 0) {
                //     cerr << "OK1" << endl;
                // }
                dp2[i+1][j+X[next]] = min(dp2[i+1][j+X[next]], dp2[i][j] + dp[next]);
            } 

            //nextと違う色で塗る場合
            if(j+dp[next] <= X[pos]) {
                // if(pos == 0) {
                //     cerr << "OK2" << endl;
                // }
                dp2[i+1][j+dp[next]] = min(dp2[i+1][j+dp[next]], dp2[i][j] + X[next]);
            }
        }
    }

    int ret = INF;
    for(int i = 0; i <= X[pos]; i++) {
        ret = min(ret, dp2[edge[pos].size()][i]);
        // if(pos == 0) {
        //     cerr << "ret: " << ret << endl;
        // }
    }

    // cerr << pos << " " << ret << endl;

    return dp[pos] = ret;
}

signed main()
{
    cin >> N;
    for(int i = 1; i < N; i++) {
        int p; cin >> p; p--;
        edge[p].push_back(i);
    }

    for(int i = 0; i < N; i++) {
        cin >> X[i];
    }

    calcSumX(0);

    for(int i = 0; i < N; i++) {
        dp[i] = INF;
    }

    if(solve(0) != INF) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

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

int main(){
    int n;
    set<int> st;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        st.insert(a);
    }
    cout << (n==st.size() ? "YES" : "NO") << endl;
    return 0;
}



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

using namespace std;

string s,t;
int n , m;
int dp[3005][3005];
int main()
{
    ios::sync_with_stdio(0);
    cin >> s >> t;
    n = s.length();
    m = t.length();
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]);
            if (s[i - 1] == t[j - 1])dp[i][j] = max(dp[i][j] , dp[i - 1][j - 1] + 1);
        }
    }
    vector<char> v;
    int i = n , j = m;
    while(i != 0 && j != 0)
    {
        if (i && dp[i][j] == dp[i - 1][j])i--;
        else if (j && dp[i][j] == dp[i][j - 1])j--;
        else if (i && j && dp[i][j] == 1 + dp[i - 1][j - 1])v.push_back(s[i - 1]) , i-- , j--;
    }
    reverse(v.begin() , v.end());
    for (int i=0;i<v.size();i++)cout << v[i];
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 35456
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==-1)
				return;
			System.out.println(Integer.toString(n, 4));
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int digits(int x) {
    int sum = 0,tmp = x;
    while(tmp > 0) {
        sum += tmp % 10;
        tmp /= 10;
    }
    return sum;
}

int main() {
    int n;
    cin >> n;
    int a,b,min = n;
    for(int i = 1; i < n; i++) {
        a = i;
        b = n-i;
        if(min > digits(a) + digits(b)) {
            min = digits(a) + digits(b);
        }
    }
    cout << min;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	N, K = ReadInt(), ReadInt()
	P := ReadInts(N)
	C = ReadInts(N)

	next = make([]int, N)
	for i := 0; i < N; i++ {
		P[i]--
		next[i] = P[i]
	}

	l = make([]int, N)
	for v := 0; v < N; v++ {
		if l[v] == 0 {
			calcL(0, v, make([]bool, N))
		}
	}

	score = make([][]int, N)
	for v := 0; v < N; v++ {
		score[v] = make([]int, l[v]+1)
	}

	ans := -1 << 60
	for v := 0; v < N; v++ {
		calcScore(0, v, v, 0)
		if K <= l[v] {
			for k := 1; k <= K; k++ {
				ans = Max(ans, score[v][k])
			}
			continue
		}
		if score[v][l[v]] <= 0 {
			for k := 1; k <= l[v]; k++ {
				ans = Max(ans, score[v][k])
			}
			continue
		}

		cycle := K/l[v] - 1
		cycleScore := cycle * score[v][l[v]]
		if cycle > 0 {
			ans = Max(ans, cycleScore)
		}
		for i := 0; i <= K-l[v]*cycle; i++ {
			k := l[v]*cycle + i
			if k == 0 {
				continue
			}
			if i <= l[v] {
				ans = Max(ans, cycleScore+score[v][i])
			} else {
				ans = Max(ans, cycleScore+score[v][l[v]]+score[v][i-l[v]])
			}
		}
	}
	fmt.Println(ans)
}

var N, K int
var C, next, l []int
var score [][]int

func calcL(depth int, visit int, seen []bool) int {
	if seen[visit] {
		l[visit] = depth
		return depth
	}
	seen[visit] = true
	l[visit] = calcL(depth+1, next[visit], seen)
	return l[visit]
}

func calcScore(depth int, start int, visit int, prefix int) {
	if depth > l[visit] {
		return
	}
	score[start][depth] = prefix
	calcScore(depth+1, start, next[visit], prefix+C[next[visit]])
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 210140
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  cin >> N;
  double x[10];
  string money;
  double total = 0;
    for(int i = 0; i < N; i++)
  {
    /* code */
    cin >> x[i] >> money;
    if(money == "JPY"){
      total += x[i];
    }else{
      total += x[i] * 380000.0;
    }
    
  }
  cout << total << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

#pragma region UnionFind
struct UnionFind
{
    vector<int> d;
    // d[x] is the index of the parent of x
    // d[x] is -size if x is a root

    UnionFind(int n) : d(vector<int>(n, -1)) {}
    int root(int x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
        {
            return false;
        }
        if (d[x] > d[y])
            swap(x, y); // x always bigger tree

        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x) { return -d[root(x)]; }
};
#pragma endregion

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uft(n);
    rep(i, m)
    {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uft.unite(x, y);
    }

    int ans = n;
    rep(i, n)
    {
        if (uft.root(i) == i)
        {
            ans -= uft.size(i) - 1;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3728
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	io := NewIo()
	defer io.Flush()
	S := io.Next()
	T := io.Next()
	N := len(S)
	M := len(T)
	A1 := make([]int, N + 1)
	B1 := make([]int, N + 1)
	A2 := make([]int, M + 1)
	B2 := make([]int, M + 1)
	for i := 0; i < N; i++ {
		if S[i] == 'A' {
			A1[i + 1] = A1[i] + 1
		} else {
			A1[i + 1] = A1[i]
		}
		if S[i] == 'B' {
			B1[i + 1] = B1[i] + 1
		} else {
			B1[i + 1] = B1[i]
		}
	}
	for i := 0; i < M; i++ {
		if T[i] == 'A' {
			A2[i + 1] = A2[i] + 1
		} else {
			A2[i + 1] = A2[i]
		}
		if T[i] == 'B' {
			B2[i + 1] = B2[i] + 1
		} else {
			B2[i + 1] = B2[i]
		}
	}
	Q := io.NextInt()
	for i := 0; i < Q; i++ {
		q := make([]int, 4)
		for j := 0; j < 4; j++ {
			q[j] = io.NextInt()
		}
		x := A1[q[1]] - A1[q[0] - 1] + 2 * (B1[q[1]] - B1[q[0] - 1])
		y := A2[q[3]] - A2[q[2] - 1] + 2 * (B2[q[3]] - B2[q[2] - 1])
		//Log("x", x)
		//Log("y", y)
		if x % 3 == y % 3 {
			io.PrintLn("YES")
		} else {
			io.PrintLn("NO")
		}
	}
}


Measured memory_bytes: 7936
INF = 10 ** 9 + 7

S = input()

dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i+1)]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j) % 13] += dp[i][j]
                dp[i+1][(mul*k+j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(mul*k+j) % 13] += dp[i][j]
            dp[i+1][(mul*k+j) % 13] %= INF
    mul = mul * 10 % 13

print(dp[len(S)][5])

Measured memory_bytes: 62300
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n;
	while (cin >> n, n){
		vector<int> vi(n);
		REP(i, n){
			string s;
			cin >> s;
			if (s == "x")s = "-1000000003";
			vi[i]=stoi(s);
		}
		int min_x = -1000000002;//?????¨??§??????x
		int max_x = 1000000002;
		bool none = false;
		int pre = vi[0];
		if (vi[0] == -1000000003){
			if (n!=1)max_x = min(max_x, vi[1] - 1);
		}
		FOR(i,1, n){
			if (pre != -1000000003){
				if (i % 2 == 0){//odd
					if (vi[i] == -1000000003){
						max_x = min(max_x, vi[i - 1] - 1);
						if (i != n - 1)max_x = min(max_x, vi[i + 1] - 1);
						
					}
					else{
						if (pre <= vi[i])
							none = true;
					}
				}
				else{//even
					if (vi[i] == -1000000003){
						min_x = max(min_x, vi[i - 1] + 1);
						if (i != n - 1)min_x = max(min_x, vi[i + 1] + 1);
					}
					else{
						if (pre >= vi[i])
							none = true;
					}
				}
			}
			else{
				if (vi[i] == -1000000003)none = true;
			}
			if (min_x > max_x){
				none = true;
				break;
			}
			pre = vi[i];
		}
		if (none)
			cout << "none" << endl;
		else if (min_x == max_x)
			cout << min_x << endl;
		else
			cout <<"ambiguous" << endl;

	}
}

Measured memory_bytes: 1228
#include<iostream>
#include<vector>
#include<climits>

using namespace std;

int A,B,C,D,N; int l[10];

const int inf = (1<<29);

int dfs(int depth, int LA, int LB, int LC){
  if( depth == N+1 ){ 
    if(LA && LB && LC){return abs(LA - A) + abs(LB - B) + abs(LC - C) - 30;}
     else{ return inf;}}
  
   int ret1 = dfs( depth+1, LA + l[depth],LB,LC) + 10 ;
   int ret2 = dfs( depth+1, LA, LB + l[depth], LC) + 10;
   int ret3 = dfs( depth+1, LA, LB, LC + l[depth]) + 10;
   int ret4 = dfs( depth+1, LA,LB,LC);
  
   return min(min(ret1,ret2),min(ret3,ret4));}
  

int main(){
 cin >> N >> A >> B >> C;
 
  for(int i = 1; i <= N; i++){ cin >> l[i];}
  cout << dfs(1,0,0,0) << endl; return 0;}
  
  

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

double n, m, d;

int main() {
    cout << fixed << setprecision(10);

    cin >> n >> m >> d;

    if (d == 0) cout << (m-1)/n << endl;
    else {
        cout << (m-1)*2*(n-d)/n/n << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
# N = "9999"
# N = "9995"
# N="1000000000"
N="1"
def answer(n)
  a = (n.to_i <= N.to_i) == (n <= N)
  b = (n.to_i > N.to_i) == (n > N)
  a || b
end

def q(n)
  puts "? #{n}"
  STDOUT.flush
#   return answer(n)
  gets.chop == ?Y
end

def x(n)
  puts "! #{n}"
  STDOUT.flush
  exit(0)
end

a = []
(1..10).each do |d|
  a << q("9"*d)
end
a.pop until a.empty? || !a[-1]

if a.size != 0
  n = ""
  a.size.times do |d|
    l, h = 0, 10
    while (l+1 < h) do
      m = (l+h)/2
    if q(n + m.to_s)
        l = m
      else
        h = m
      end
    end
    n += l.to_s
  end
  %w(00 10 20 30 40 50 60 70 80 90).each do |w|
    x(n + w[0]) if q(n + w)
  end
end

1.upto(9) do |d|
  next if q((10**d).to_s)
  n = "9"*(d-1)
  %w(00 10 20 30 40 50 60 70 80 90).each do |w|
    next if d==1 && w=="00"
    x(n + w[0]) if q(n + w)
  end
end
x(1)


Measured memory_bytes: 4172
N,Q = (map(int,input().split()))
for a in range(N,-1,-1):
    A = a*10000
    if A > Q:
        continue
    if (a==N)and(A == Q):
        print("{0} 0 0".format(a))
        exit()
    for b in range(N-a,-1,-1):
        B = A+b*5000
        if B > Q:
            continue
        if (a+b==N)and(B == Q):
            print("{0} {1} 0".format(a,b))
            exit()
        if ((Q-B)%1000==0)and((Q-B)/1000==(N-a-b)):
            print("{0} {1} {2}".format(a,b,int((Q-B)/1000)))
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3064
x, y, a, b, c = gets.split.map(&:to_i)
reds = gets.split.map(&:to_i).sort { |a, b| b <=> a }
greens = gets.split.map(&:to_i).sort { |a, b| b <=> a }
transparents = gets.split.map(&:to_i).sort { |a, b| b <=> a }

eaten = reds[0...x] + greens[0...y]
eaten.sort!
[transparents.size, eaten.size].min.times do |i|
  if eaten[i] < transparents[i]
    eaten[i] = transparents[i]
  end
end
puts eaten.inject(:+)


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 (b<a) { a=b; return 1; } return 0; }



int k;
void solve(){
	cin >> k;
	
	queue<i64> q;
	for(int i = 1; i < 10; i++){
		q.push(i);
	}
	while(1){
		i64 p = q.front(); q.pop();
		k--;
		if(k == 0){
			cout << p << endl;
			return;
		}
		for(int i = 0; i < 10; i++){
			if(abs(p%10 - i) <= 1) q.push(p*10+i);
		}
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 1792
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [list(map(int, input().split())) for _ in range(q)]
dic = Counter(a)
S = sum(a)
for i in range(q):
    (b, c) = l[i] 
    num = dic[b]
    S -= b*num
    dic[b] = 0
    if dic[c] == 0:
        dic[c] = num
    else:
        dic[c] += num
    S += c*num
    print(S)

Measured memory_bytes: 40236
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>

using namespace std;

long long mod = 1000000007;

long long pow(long long x, long long k)
{
    if (k == 0)
    {
        return 1LL;
    }
    long long temp = pow(x, k / 2);
    if (k % 2 == 1)
    {
        return (((temp * temp) % mod) * x) % mod;
    }
    else
    {
        return (temp * temp) % mod;
    }
}

long long modular_inverse(long long x)
{
    return pow(x, mod - 2);
}

long long binomial(long long n, long long k)
{
    long long rez = 1;
    for (int i = n - k + 1; i <= n; i++)
    {
        rez *= i;
        rez %= mod;
    }
    long long temp = 1;
    for (int i = 1; i <= k; i++)
    {
        temp *= i;
        temp %= mod;
    }
    rez *= modular_inverse(temp);
    rez %= mod;
    return rez;
}

int main()
{
    int n;
    cin >> n;
    vector<long long> v(n);
    long long sm1 = 0, sm2 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        sm1 += v[i];
    }
    long long rez = 999999999999999;
    for (int i = 0; i < n; i++)
    {
        rez = min(rez, abs(sm1 - sm2));
        sm2 += v[i];
        sm1 -= v[i];
    }
    rez = min(rez, abs(sm1 - sm2));
    cout << rez << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	ll a,b;
	cin >> a >> b;
	ll x = 0;
	for(ll i = a/4 * 4; i < a; ++i){
		x^=i;	
	}
	for(ll i = b/4 * 4; i <= b; ++i){
		x^=i;	
	}
	cout << x << '\n';
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long int a,b,x,c,i;
	int count=0;
	scanf("%lld%lld%lld",&a,&b,&x);
	c=b/x-a/x;

		if (a%x==0)
		count++;

	printf("%lld",c+count);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
T = list(map(int,input().split()))
T.insert(0,0)
M = int(input())
X = [list(map(int,input().split())) for _ in range(M)] 
tot = sum(T)
for i in range(M):
    p,x = X[i]
    print(tot-T[p]+x)

Measured memory_bytes: 62744
N, M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
p = []
vote = 0
for i in range(N):
    vote = vote + a[i]
for i in range(N):
    if a[i] >= vote/(4*M):
        p.append(0)
if len(p) >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define FOR(i, a, b) for (int i = a, i##_len = (b); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define EPS (1e-7)
#define INF (1e9)

using namespace std;

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

  int n;
  cin >> n;
  int minv, max_prof = -INF;
  cin >> minv;

  REP(i, n - 1) {
    int v;
    cin >> v;

    if (v - minv > max_prof) {
      max_prof = v - minv;
    }
    if (v < minv) {
      minv = v;
    }
  }

  cout << max_prof << endl;
}



Measured memory_bytes: 3216
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).
 
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

main :-
  get_string(S),
  string_chars(S,L),
  L = [H1,H|_],
  (H='B' -> writeln('ARC');writeln('ABC')).

Measured memory_bytes: 8056
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<int> g[1010],rt;
bool gb[1010][1010],visited[1010];
int r[1010];

bool dfs(int v, int s){
	int i;
	if(v==s && visited[v]){
		return true;
	}else if(visited[v]){
		return false;
	}
	visited[v] = true;
	for(i=(g[v].l_ength()-1); i>=0; --i){
		if(dfs(g[v][i],s)){
			r[v] = g[v][i];
			return true;
		}
	}
	return false;
}

int main(void){
	int n,m,t,i,j,a,b,cnt=0;
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> a >> b;
		--a; --b;
		gb[a][b] = true;
		g[a].push_back(b);
	}
	for(i=0; i<n; ++i){
		fill(visited,visited+n,false);
		if(dfs(i,i)){
			a = i;
			rt.push_back(a);
			while(r[a]!=i){
				rt.push_back(r[a]);
				a = r[a];
			}
			t = rt.l_ength();
			for(i=1; i<t; ++i){
				for(j=0; j<t; ++j){
					if(gb[rt[(j+i)%t]][rt[j]]){
						cout << (i+1) << endl;
						for(a=0; a<=i; ++a){
							cout << (rt[(j+a)%t]+1) << endl;
						}
						return 0;
					}
				}
			}
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1408
import java.util.*;

class Main {

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

		int n = sc.nextInt();
		int[] a = new int[n];

		long sum = 0;
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
			sum += (long)a[i];
		}
		sum -= (long)2 * a[n - 1];
		
		long min = sum;

		for(int i=n-2; i>=1; i--){
			sum -= (long)2 * a[i];
			if(Math.abs(sum) < Math.abs(min)){
				min = sum;
			}
		}

		System.out.println(Math.abs(min));
	}
}


Measured memory_bytes: 65444
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = Integer.parseInt(s.nextLine());
        String[] Sz = new String[N];
        for (int i = 0; i < N; i++){
            Sz[i] = s.nextLine();
        }
        HashMap<String,Integer> map = new HashMap<String,Integer>();
        for (int i = 0; i < N; i++){
            if (!map.keySet().contains(Sz[i])){
                map.put(Sz[i],1);
            } else {
                map.put(Sz[i],map.get(Sz[i]) + 1);
            }
        }
        if (map.get("AC") == null){
            System.out.println("AC x 0");
        } else {
            System.out.println("AC x "+map.get("AC"));
        }
        if (map.get("WA") == null){
            System.out.println("WA x 0");
        } else {
            System.out.println("WA x "+map.get("WA"));
        }
        if (map.get("TLE") == null){
            System.out.println("TLE x 0");
        } else {
            System.out.println("TLE x "+map.get("TLE"));
        }
        if (map.get("RE") == null){
            System.out.println("RE x 0");
        } else {
            System.out.println("RE x "+map.get("RE"));
        }
        
    }
}

Measured memory_bytes: 66292
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m;
V s,z;
V &Me(const V &_x,const V &_y){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
	return z;
}
V &Mx(const V &_x){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_x[slice(j,n,n)]).sum()%m;
	return z;
}
void O(const V &r){
	int i=0;
    for(;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		s.resize(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		V x(n*n);
		V e(n*n);
		//e.resize(0);
		//e.resize(n*n);
		z.resize(n*n);

		x[0]=b;
		x[1]=c;
		e[0]=1;
		for(i=1;i<n-1;i++){
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			x[i*n+i+1]=c;
			e[i*n+i]=1;
		}
		x[i*n+i-1]=a;
		x[i*n+i]=b;
		e[i*n+i]=1;
		for(;t;t>>=1){
			if(t&1)e=Me(e,x);
			x=Mx(x);
		}
		O(e);
	}
}

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

int main() {
	// your code goes here
	char c;
	cin >> c;
	if((c=='a')||(c=='e')||(c=='o')||(c=='u')||(c=='i')){
		cout << "vowel" << endl;
	}
	else cout << "consonant" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new
				InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		long A = Long.parseLong(strs[0]);
		long B = Long.parseLong(strs[1]);
		long C = Long.parseLong(strs[2]);
		long K = Long.parseLong(strs[3]);
		if(K%2==0){
			System.out.println(A-B);
		}else{
			System.out.println(-A+B);
		}
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {
  ll N, K;
  cin >> N >> K;
  N %= K;
  ll ans = min(abs(N - K), abs(N));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
 
char S[3030],T[3030]; int D[3030][3030];
 
int main()
{
	scanf ("%s %s",S+1,T+1);
 
	int n = 0, m = 0;
	while (S[n+1]) n++;
	while (T[m+1]) m++;
 
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++){
		if (S[i] == T[j]) D[i][j] = D[i-1][j-1] + 1;
		else D[i][j] = max(D[i-1][j], D[i][j-1]);
	}
 
	int i = n, j = m;
	string r;
	while (i && j){
		if (S[i] == T[j]){
			r += S[i];
			i--; j--;
		}
		else if (D[i-1][j] < D[i][j-1]) j--;
		else i--;
	}
	reverse(r.begin(),r.end());
	puts(r.c_str());
 
	return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; } return false; }
//Write From this Line

int main()
{
	ll k;
	cin >> k;

	ll n = 50;
	vector<ll> ans(50);
	rep(i,50){
		ans[i] = 49 + k / 50;
	}
	k %= 50;
	rep(i,k){
		ans[i] += n + 1;
		rep(j,n) ans[j]--;
	}
	cout << n << endl;
	rep(i,n){
		cout << ans[i];
		if(i != n - 1){
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
////////////////////////////////////////////////////////////////////

int x;
signed main(){
  cin>>x;int ans = (x/11)*2;
  if(1 <= x-11*(x/11) && x-11*(x/11) <= 6)ans++;
  else if(7 <= x-11*(x/11))ans+= 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static int[] dx = {-1, 0, 1, 0};
	static int[] dy = {0, -1, 0, 1};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int[] n = new int[N];
			int[] d = new int[N];
			int[] x = new int[N];
			int[] y = new int[N];
			for (int i = 1; i < N; i++) {
				n[i] = sc.nextInt();
				d[i] = sc.nextInt();
			}
			x[0] = 0; y[0] = 0;
			for (int i = 1; i < N; i++) {
				x[i] = x[n[i]] + dx[d[i]];
				y[i] = y[n[i]] + dy[d[i]];
			}
			int maxX, maxY, minX, minY;
			maxX = maxY = -1000;
			minX = minY = 1000;
			for (int i = 0; i < N; i++) {
				if (maxX < x[i]) {
					maxX = x[i];
				}
				if (minX > x[i]) {
					minX = x[i];
				}
				if (maxY < y[i]) {
					maxY = y[i];
				}
				if (minY > y[i]) {
					minY = y[i];				
				}
			}
			int w = maxX - minX + 1;
			int h = maxY - minY + 1;
			System.out.println(w + " " + h);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << 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) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N;
int B[110];

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N;
    REP(i, N - 1) cin >> B[i];
    B[N - 1] = INF;
    int ans = 0;
    REP(i, N) {
        int tmp = B[i];
        if (i > 0) CHMIN(tmp, B[i - 1]);
        ans += tmp;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define MAX 20
#define GEM 1
using namespace std;
int main(){
	while(true){
		int map[MAX+1][MAX+1]={{0,},};
		int ri=10,rj=10;
		int n,m;
		int cnt = 0;

		cin>>n;
		if(n==0)break;
		for(int i = 0; i < n; ++i){
			int ji,jj;
			cin>>ji>>jj;
			map[MAX-jj][ji]=GEM;
		}
		cin>>m;
		for(int i = 0; i < m; ++i){
			char dir;
			int len;
			cin>>dir>>len;
			switch(dir){
				case 'N':
					for(int j = 0; j < len; ++j){
						--ri;
						if( map[ri][rj] == GEM ){
							map[ri][rj] = 0;
							++cnt;
						}
					}
					break;
				case 'E':
					for(int j = 0; j < len; ++j){
						++rj;
						if( map[ri][rj] == GEM ){
							map[ri][rj] = 0;
							++cnt;
						}
					}
					break;
				case 'W':
					for(int j = 0; j < len; ++j){
						--rj;
						if( map[ri][rj] == GEM ){
							map[ri][rj] = 0;
							++cnt;
						}
					}
					break;
				case 'S':
					for(int j = 0; j < len; ++j){
						++ri;
						if( map[ri][rj] == GEM ){
							map[ri][rj] = 0;
							++cnt;
						}
					}
					break;
			}
		}
		if( cnt == n )
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

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

int main(void){
    int i,j,n,w;
    char h;
    int cards[4][13];
    for (i=0; i<4; i++) {
        for (j=0; j<13; j++) {
            cards[i][j] = j+1;
        }
    }
    cin >> n ;
    for (i=0; i<n; i++) {
        cin >> h >> w;
        if (h=='S') {
            cards[0][w-1]= NULL;
        }else if (h=='H') {
            cards[1][w-1]= NULL;
        }else if (h=='C') {
            cards[2][w-1]= NULL;
        }else if (h=='D') {
            cards[3][w-1]= NULL;
        }
    }
    for (i=0; i<4; i++) {
        for (j=0; j<13; j++) {
            if(cards[i][j]!=NULL)
                switch (i) {
                    case 0:
                        cout << "S " << cards[0][j]<< "\n";
                        break;
                    case 1:
                        cout << "H " << cards[1][j]<< "\n";
                        break;
                    case 2:
                        cout << "C " << cards[2][j]<< "\n";
                        break;
                    case 3:
                        cout << "D " << cards[3][j]<< "\n";
                        break;
                }
        }
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h,n,ww,hh;cin>>w>>h>>n;
  int xM=0,xm=w,yM=0,ym=h;
  vector<int> x(n),y(n),a(n);
  for(int i=0;i<n;i++)cin>>x.at(i)>>y.at(i)>>a.at(i);
  for(int j=0;j<n;j++){
    if(a.at(j)==1)xM=max(xM,x.at(j));
    else if(a.at(j)==2)xm=min(xm,x.at(j));
    else if(a.at(j)==3)yM=max(yM,y.at(j));
    else ym=min(ym,y.at(j));
  }
  ww=max(0,xm-xM);
  hh=max(0,ym-yM);
  cout<<ww*hh<<endl;
}
                             

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,g;
    cin>>d>>g;
    vector<int> p(d);
    vector<int> c(d);
    for(int i=0;i<d;i++){
        cin>>p[i]>>c[i];
    }
    int ans=1e9;
    for(int i=0;i<(1<<d);i++){
        int sum=0;
        int max_p=-1;
        int count=0;
        for(int j=0;j<d;j++){
            if((bool)(i&(1<<j))){
                sum+=100*(j+1)*p[j]+c[j];
                count+=p[j];
            }
            else{
                max_p=j;
            }
        }
        if(g>sum){
            int point=100*(max_p+1);
            int need=(g-sum+point-1)/point;
            if(p[max_p]<need)continue;
            count+=need;
        }
        ans=min(ans,count);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
𝓐𝓾𝓽𝓱𝓸𝓻:-

╭━━━┳━━━┳╮╱╭┳━━━┳━━━┳━━╮╭╮╱╭╮
┃╭━╮┃╭━╮┃┃╱┃┃╭━╮┃╭━╮┃╭╮┃┃┃╱┃┃  
┃╰━━┫┃╱┃┃┃╱┃┃╰━╯┃┃╱┃┃╰╯╰┫╰━╯┃
╰━━╮┃╰━╯┃┃╱┃┃╭╮╭┫╰━╯┃╭━╮┃╭━╮┃
┃╰━╯┃╭━╮┃╰━╯┃┃┃╰┫╭━╮┃╰━╯┃┃╱┃┃
╰━━━┻╯╱╰┻━━━┻╯╰━┻╯╱╰┻━━━┻╯╱╰╯  

*/

#include <bits/stdc++.h> 
using namespace std; 
#define int long long int
#define REDBULL ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl "\n"
// #define MAX 131079
int power(int x,  int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 void sumXOR(int arr[], int n) 
{ 
   int sum = 0; 
    for (int i = 0; i < 64; i++)  
    { 
        //  Count of zeros and ones 
        int zc = 0, oc = 0;  
          
        // Individual sum at each bit position 
         int idsum = 0;  
        for (int j = 0; j < n; j++) 
        { 
            if (arr[j] % 2 == 0) 
                zc=(zc+1); 
            else
                oc=(oc+1); 
            arr[j] /= 2; 
        } 
          
        idsum = ( (oc )%mod* (zc)%mod * power(2,i,mod)%mod)%mod;  
  
        // final sum     
        sum = ((sum)%mod+idsum%mod)%mod;  
    } 
    cout<< sum%mod<<endl; 
} 
  
int32_t main() 
{ 
	REDBULL
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	
	}
		sumXOR(a,n);
	return 0; 
} 


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

vector<int> dist;
/*
int gcd(int a, int b)
{
    if (a>b)
    {
        return gcd(b, a);
    }
    if (a==0)
    {
        return b;
    }
    if (b%a == 0)
    {
        return abs(a);
    }

    return gcd(b%a, a);
}
*/
int main()
{
    int n, x;
    cin >> n >> x;

    for (int i=0; i<n; i++)
    {
        int a;
        cin >> a;
        dist.push_back(a-x);
    }
    int g=dist[0];
    for (int i=0; i<n; i++)
    {
        g = __gcd(g, dist[i]);
    }
    cout << abs(g) << "\n";
    return 0;
}


Measured memory_bytes: 892
def test():
    n = int(input())
    s = 0; t = 0; index_ = 0
    for i in range(n):
        a = int(input())
        if s < a:
            index_ = i
            s = a
        elif t < a and a <= s:
            t = a
    for i in range(n):
        if index_ == i:
            print(t)
        else:
            print(s)


if __name__ == "__main__":
    test()


Measured memory_bytes: 4540
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    vector<pair<int,int>> v(n);
    for(int i=0;i<n;++i){
        int ai;cin>>ai;
        v[i] = {ai,i+1};
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    
    multiset<int> st;
    st.insert(0);
    st.insert(0);
    st.insert(n+1);
    st.insert(n+1);
    ll ret = 0ll;
    for(auto vi: v){
        int num = vi.first;
        int id = vi.second;
        auto it = st.lower_bound(id);
        int r1 = *it;it++;
        int r2 = *it;it--;
        it--;
        int l1 = *it;
        it--;
        int l2 = *it;
        ret += 1ll*num*(l1 - l2) * (r1 - id);
        ret += 1ll*num*(r2 - r1) * (id - l1);
        st.insert(id);
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 5760