akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {

        public static void Main(String[] args)
        {
            var diceSeed = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var RollDest = Console.ReadLine();

            var dice = new Dice(diceSeed[0], diceSeed[1], diceSeed[2], diceSeed[3], diceSeed[4], diceSeed[5]);

            dice.Roll(RollDest);

            Console.WriteLine(dice.top);


        }



    }
    class Dice
    {
        public int top, front, right, left, back, bottom;

        public Dice(int dice0, int dice1, int dice2, int dice3, int dice4, int dice5)
        {
            top = dice0;
            front = dice1;
            right = dice2;
            left = dice3;
            back = dice4;
            bottom = dice5;

        }


        public void RollS()
        {

            int pastFront = front;
            int pastTop = top;
            int pastBack = back;
            int pastBottom = bottom;

            top = pastBack;
            front = pastTop;
            back = pastBottom;
            bottom = pastFront;

        }

        public void RollN()
        {
            int pastFront = front;
            int pastTop = top;
            int pastBack = back;
            int pastBottom = bottom;

            top = pastFront;
            front = pastBottom;
            back = pastTop;
            bottom = pastBack;
        }

        public void RollE()
        {
            int pastTop = top;
            int pastRight = right;
            int pastLeft = left;
            int pastBottom = bottom;

            top = pastLeft;
            right = pastTop;
            left = pastBottom;
            bottom = pastRight;
        }

        public void RollW()
        {
            int pastTop = top;
            int pastRight = right;
            int pastLeft = left;
            int pastBottom = bottom;

            top = pastRight;
            right = pastBottom;
            left = pastTop;
            bottom = pastLeft;
        }

        private void Roll(Char rollSp)
        {
            switch (rollSp)
            {
                case 'S':
                    RollS();
                    break;

                case 'N':
                    RollN();
                    break;

                case 'E':
                    RollE();
                    break;

                case 'W':
                    RollW();
                    break;
            }

        }

        public void Roll(String RollDest)
        {
            RollDest.ToList().ForEach(x => Roll(x));

        }

    }


}



Measured memory_bytes: 20456
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,A,B= (int(x) for x in input().split())
v = list(map(int, input().strip().split()))
v.sort(reverse=True)
print(sum(v[0:A])/A)
ctall = 0
ct = 0
for i in range (A):
    if v[i] == v[A-1]:
        ct += 1
answer = 0
for i in range (N):
    if v[i] == v[A-1]:
        ctall += 1
    if v[i] < v[A-1]:
        break
if (ct == A):
    for i in range(A,min(ctall+1,B+1)):
        answer += combinations_count(ctall, i)
    print(answer)
else: print(combinations_count(ctall, ct))


Measured memory_bytes: 3064
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;

int32_t num[3];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	std::string s;
	in >> s;
	for (auto& i : s) {
		num[i - 'a']++;
	}

	{
		std::sort(num, num + 3);
		int32_t min = num[0];
		for (auto& i : num) { i -= min; }
	}
	if (num[2] >= 2) { out << "NO" << endl; }
	else { out << "YES" << endl; }


	return 0;
}
#endif


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string s;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'a'&&s[i + 1] == 'p'&&s[i + 2] == 'p'&&s[i + 3] == 'l'&&s[i + 4] == 'e') {
			cout << "peach";
			i += 4;
		}
		else if (s[i] == 'p'&&s[i + 1] == 'e'&&s[i + 2] == 'a'&&s[i + 3] == 'c'&&s[i + 4] == 'h'){
			cout << "apple";
			i += 4;
		}
		else cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3008
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>

using namespace std;

class SegTree{
public:
    int n;
    int defaultValue;
    vector<int> dat;

    SegTree(int m, int value){
        n = 1;
        while(n < m){
            n *= 2;
        }
        dat = vector<int>(2 * n - 1, value);
        defaultValue = value;
    }

    void update(int i, int value){
        i += n - 1;
        dat[i] = value;
        while(i > 0){
            i = (i - 1) / 2;
            dat[i] = ope(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    int query(int a, int b){
        return query(a, b, 0, 0, n);
    }
private:
    int query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l){
            return defaultValue;
        }
        if(a <= l && r <= b){
            return dat[k];
        }
        else{
            int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return ope(vl, vr);
        }
    }

    int ope(int a, int b){
        return min(a, b);
    }
};

int main(){

    int n, q;
    cin >> n >> q;
    int initialValue = pow(2.0, 31.0) - 1.0;
    SegTree sg(n, initialValue);
    int com, x, y;
    for(int i = 0; i < q; i++){
        cin >> com >> x >> y;
        if(com == 0){
            sg.update(x, y);
        }
        else{
            cout << sg.query(x, y + 1) << "\n";
        }
    }

    return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    REP(_, n) {
        int a; cin >> a;
        if (a % 2 == 0) {
            if (a % 3 == 0 || a % 5 == 0) {
                continue;
            } else {
                cout << "DENIED" << endl;
                return 0;
            }
        } else {
            continue;
        }
    }
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 888
#include<stdio.h>

int binarySearch(int key, int a[], int num){
   int left = 0;
   int right = num;
   int mid = 0;

   while(1){
      mid = (left + right) / 2;

      if(a[mid] == key){
         return 1;
      }else if(key < a[mid]){
         right = mid;
      }else{
         left = mid + 1;
      }

      if(left >= right){
         return 0;
         break;
      }
   }


}



int main () {

   int s[100000] = {0};
   int t = 0;
   int n, q, i;
   int count = 0;

   scanf("%d", &n);

   for(i = 0; i < n; i++){
      scanf("%d", &s[i]);
   }

   scanf("%d", &q);

   for(i = 0; i < q; i++){
      scanf("%d", &t);

      if(binarySearch(t,s,n)){
         count++;
      }
   }

   printf("%d\n", count);

   return 0;

}


   

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

struct dsu {
 public:
  dsu() : _n(0) {}
  dsu(int n) : _n(n), parent_or_size(n, -1) {}

  int merge(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    int x = leader(a), y = leader(b);
    if (x == y) return x;
    if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
    parent_or_size[x] += parent_or_size[y];
    parent_or_size[y] = x;
    return x;
  }

  bool same(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    return leader(a) == leader(b);
  }

  int leader(int a) {
    assert(0 <= a && a < _n);
    if (parent_or_size[a] < 0) return a;
    return parent_or_size[a] = leader(parent_or_size[a]);
  }

  int size(int a) {
    assert(0 <= a && a < _n);
    return -parent_or_size[leader(a)];
  }

  std::vector<std::vector<int>> groups() {
    std::vector<int> leader_buf(_n), group_size(_n);
    for (int i = 0; i < _n; i++) {
      leader_buf[i] = leader(i);
      group_size[leader_buf[i]]++;
    }
    std::vector<std::vector<int>> result(_n);
    for (int i = 0; i < _n; i++) {
      result[i].reserve(group_size[i]);
    }
    for (int i = 0; i < _n; i++) {
      result[leader_buf[i]].push_back(i);
    }
    result.erase(
        std::remove_if(result.begin(), result.end(),
                       [&](const std::vector<int>& v) { return v.empty(); }),
        result.end());
    return result;
  }

 private:
  int _n;
  // root node: -1 * component size
  // otherwise: parent
  std::vector<int> parent_or_size;
};

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

  dsu d(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    d.merge(a - 1, b - 1);
  }

  for (int i = 0; i < n; i++) {
    if (d.same(0, i) == false) {
      d.merge(0, i);
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int P[10], Q[10], R[10];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i) cin >> P[i];
	for(int i=0; i<N; ++i) cin >> Q[i];
	for(int i=0; i<N; ++i) R[i]=i+1;
	int pnum, qnum, now=0;
	do{
		bool pf=true, qf=true;
		for(int i=0; i<N; ++i){
			pf=pf&&(P[i]==R[i]);
			qf=qf&&(Q[i]==R[i]);
		}
		if(pf) pnum=now;
		if(qf) qnum=now;
		++now;
	}while(next_permutation(R, R+N));
	cout << abs(pnum-qnum) << endl;
	return 0;
}

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

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	ll noOfStools = 0;
	for(int i=0, x=0, mx=0; i<n; i++){
		cin >> x;
		if(x < mx)
			noOfStools += 1LL * (mx - x);
		else
			mx = x;
	}
	cout << noOfStools << "\n";
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long k = sc.NextLong();
        long[] a = sc.LongArray();

        long[] count = new long[n + 1];
        for (long i = 0; i < count.Length; i++)
        {
            count[i] = -1;
        }

        long loopStart = 0;
        long loopSpan = 0;
        long current = 1;
        long step = 0;
        while (true)
        {
            if (count[current] == -1)
            {
                count[current] = step;
            }
            else
            {
                loopStart = count[current];
                loopSpan = step - count[current];
                break;
            }
            current = a[current - 1];
            step++;
        }

        if (loopSpan != 0 && k > loopStart)
        {
            k = loopStart + ((k - loopStart) % loopSpan);
        }

        long answer = 0;

        for (long i = 0; i <= n; i++)
        {
            if (count[i] == k)
            {
                answer = i;
                break;
            }
        }

        if (answer == 0)
        {
            answer = 1;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 45348
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n);i<(N);i++)
#define RREP(i,n,N) for(ll i=(N-1);i>=(n);i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a,b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod= 1e9+7;
const ll inf = 1e18;

ll d[10010];
ll N, M, T;
ll a[110];

int main(){
    while(cin>>N>>M>>T && N != 0){

        REP(i,0,N) cin>>a[i];

        REP(i,0,10010) d[i] = 0;

        REP(i,0,N){
            d[max(0LL,a[i]-M)]++;
            d[min(T,a[i]+M)]--;
        }

        REP(i,1,T+1){
            d[i] += d[i-1];
        }

        ll ans = 0;
        REP(i,0,T+1){
            if(d[i] > 0) ans++;
        }

        cout<<T-ans<<endl;

        return 0;
    }
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  string S;
  cin >> S;
  int N = S.size();

  vector<bool> dict(26, true);
  for (int i = 0; i < N; ++i) {
    dict[S[i] - 'a'] = false;
  }
  for (int i = 0; i < 26; ++i) {
    if (dict[i]) {
      cout << S << char(i + 'a') << endl;
      return 0;
    }
  }

  dict[S[N - 1] - 'a'] = true;
  for (int i = N - 2; i >= 0; --i) {
    for (char next = S[i] + 1; next <= 'z'; ++next) {
      if (next <= 'z' && dict[next - 'a']) {
        S[i] = next;
        cout << S.substr(0, i + 1) << endl;
        return 0;
      }
    }
    dict[S[i] - 'a'] = true;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
int main(){
  int a,b,res,c;
  scanf("%d%d",&a,&b);
  if(a>b){
    res=b;
    c=a;
  }
  else{
    res=a;
    c=b;
  }
  for(int i=0;i<c;i++){
    printf("%d",res);
  }
  return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {

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

		char[] array = x.toCharArray();

		if((array[0] == array[1] && array[1] == array[2]) || (array[1] == array[2] && array[2] == array[3]) ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

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

Measured memory_bytes: 3200
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int n, a[100009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int c = unique(a, a + n) - a;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

a,b,h,m = na()
p = h*30+m*0.5
q = m*6
d = p-q

print(math.sqrt((b-a*math.cos(math.radians(d)))**2 + (a*math.sin(math.radians(d)))**2 ))

Measured memory_bytes: 9520
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n, m, c;
    cin >> n >> m >> c;

    vi b(m);
    for (int j = 0; j < m; j++)
    {
        cin >> b[j];
    }

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int sum = 0;
        for (int j = 0; j < m; j++)
        {
            int a;
            cin >> a;
            sum += a * b[j];
        }
        sum += c;
        if (sum > 0)
        {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

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

int main(){
    string s;
    int n;
    cin >> n >> s;
    int l=s.length();
    rp(i,l){
        s.at(i)+=n;
        if(s.at(i)>90) s.at(i)-=26;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;

// ユークリッドの互除法
LL extgcd(LL a, LL b, LL &x, LL &y)
{
	LL g = a; x = 1; y = 0;
	if (b != 0)
	{
		g = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	return g;
}

// 逆元
LL mod_inverse(LL a, LL m)
{
	LL x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

// 階乗
std::vector<LL>fact;
void mod_fact(LL n, LL m)
{
	fact.resize(n + 1);
	fact[0] = 1;
	for (LL i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i%m;
}

int main()
{
	LL N;
	in >> N;
	std::vector<LL>A(N);
	rep(i, N) in >> A[i];

	std::vector<LL>B(N + 1);
	LL perm = 0, ans = 0;
	mod_fact(N, mod);
	rep(i, N)
	{
		B[i] = (fact[N] * mod_inverse(i + 1, mod)) % mod;
		(perm += B[i]) %= mod;
	}
	rep(i, N)
	{
		(ans += (A[i] * perm) % mod) %= mod;
		if (i < N - 1)
		{
			(perm += B[i + 1]) %= mod;
			((perm -= B[N - i - 1]) += mod) %= mod;
		}
	}

	out << ans << std::endl;
}


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

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


using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define debug(x) cerr << #x << ": " << x << "\n"
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;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}







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

    
    int n;
    cin>>n;
    
    int t=1;
   for(int i =1;i<=n;i++){
      
      if(t>n){
          break;
      } 
      t=pow(2,i);
      
   }
   cout<<t/2<<endl;
}


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

using namespace std;

const int maxn = 50 + 10;

int a, b, c, f[maxn][maxn][maxn];

int main()
{
  memset(f, 0x3f, sizeof(f));
  scanf("%d%d%d", &a, &b, &c);
  f[a][b][c] = 0;
  for (int i = a; i <= 52; ++i)
    for (int j = b; j <= 52; ++j)
      for (int k = c; k <= 52; ++k)
        f[i + 1][j + 1][k] = min(f[i + 1][j + 1][k], f[i][j][k] + 1),
        f[i + 1][j][k + 1] = min(f[i + 1][j][k + 1], f[i][j][k] + 1),
        f[i][j + 1][k + 1] = min(f[i][j + 1][k + 1], f[i][j][k] + 1),
        f[i + 2][j][k] = min(f[i + 2][j][k], f[i][j][k] + 1),
        f[i][j + 2][k] = min(f[i][j + 2][k], f[i][j][k] + 1),
        f[i][j][k + 2] = min(f[i][j][k + 2], f[i][j][k] + 1);
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < 55; ++i)
    ans = min(ans, f[i][i][i]);
  printf("%d", ans);
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a;
	scanf("%d",&a);
	
	if(a==0){
		printf("0\n");
	}
	else if(a==100){
		printf("1\n");
	}
	else if(a==10){
		printf("1\n");
	}
	else if(a==1){
		printf("1\n");
	}
	else if(a==110){
		printf("2\n");
	}
	else if(a==11){
		printf("2\n");
	}
	else if(a==101){
		printf("2\n");
	}
	else if(a==111){
		printf("3\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
Module Main
    Sub Main(args As String())
        Dim S As Integer = Integer.Parse(Console.ReadLine)
        Dim X As Integer = 0
        Dim A As Integer = S \ 500
        Dim B As Integer = S Mod 500
        Dim C As Integer = B \ 5
        Dim D As Integer = C * 5
        Dim E As Integer = A * 1000
        X = D + E
        Console.WriteLine(X.ToString)
    End Sub
End Module


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,s,t) for(int i=s ; i<t ; i++)
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  string s; cin >> s;
  vector<int> l(s.size(),0),r(s.size(),0);
  int cnt = 0;
  rep(i,0,s.size()-1){
    if(s[i]=='R'){
      cnt++;
      if(s[i+1]=='L'){
        l[i+1] = cnt/2; l[i] = (cnt+1)/2;
        cnt = 0;
      }
    }else{
      cnt = 0;
    }
  }
  cnt = 0;
  for(int i=s.size()-1 ; i>=1 ; i--){
    if(s[i]=='L'){
      cnt++;
      if(s[i-1]=='R'){
        l[i-1] += cnt/2; l[i] += (cnt+1)/2;
        cnt = 0;
      }
    }else{
      cnt = 0;
    }
  }
  rep(i,0,s.size()){
    cout << l[i] << " " ;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



vector<bool> f;

int main() {
    int m, n;
    cin >> m >> n;
    
    while(m | n){
        int k = 0;
        f.assign(8000000, false);
        for(int i = 2; i < 8000000; i++){
            if(!f[i] && i >= m){
                if(k < n){
                    k++;
                    for(int j = i; j < 8000000; j += i){
                        f[j] = true;
                    }
                }
                
                if(!f[i]){
                    cout << i << '\n';
                    break;
                }
            }
        }
        
        cin >> m >> n;
    }
}


Measured memory_bytes: 3880
# frozen_string_literal: true

def factor(n)
  return [1] if n == 1

  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n`.split.map(&:to_i)
end

# Example: factors(100) => {2=>2, 5=>2}
def factors_and_num(n)
  factors = factor(n)
  ret = Hash.new(0)
  factors.each do |i|
    ret[i] += 1
  end
  ret
end

def uniq_factor(n)
  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n|uniq`.split.map(&:to_i)
end

sx, sy, tx, ty = gets.chomp.split(' ').map(&:to_i)

x = tx - sx
y = ty - sy

puts 'U' * y + 'R' * x + 'D' * y + 'L' * x + 'L' + 'U' * (y + 1) + 'R' * (x + 1) + 'D' + 'R' + 'D' * (y + 1) + 'L' * (x + 1) + 'U'


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll a,b;
	cin>>a>>b;
	ll x=1;
	while(1)
	{
		ll y=(x*8)/100;
		ll z=(x*10)/100;
		if(y==a && z==b)
		{
			cout<<x<<"\n";
			return 0;
		}
		if(y>a || z>b)
		{
			cout<<"-1\n";
			return 0;
		}
		x++;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int a[2000];

int main(){
	
	vector<int> v;
	vector<int>::iterator ite;
	
	int m, n;
	
	while(true){
		
		cin >> n >> m;
		
		if(n == 0 && m == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		a[n] = 0;
		
		v.erase(v.begin(), v.end());
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				v.push_back(a[i] + a[j]);
			}
		}
		
		sort(v.begin(), v.end());
		
		int ans = 0;
		
		for(int i = 0; i < (n + 1) * (n + 1); i++){
			if(v.at(i) > m){
				break;
			}
			ite = upper_bound(v.begin(), v.end(), m - v.at(i));
			ite--;
			if(*ite + v.at(i) > ans){
				ans = *ite + v.at(i);
			}
		}
		
		printf("%d\n", ans);
		
	}
	return 0;
}

Measured memory_bytes: 5448
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double w, h, x, y, r;
    bool check_x(false), check_y(false), check_w(false), check_h(false);

    cin >> w >> h >> x >> y >> r;

    if (2*w >= 2*x)
        check_w = true;

    if (2*h >= 2*y)
        check_h = true;

    if (w - x >= r && x >= r)
        check_x = true;

    if (h - y >= r && y >= r)
        check_y = true;

    if (check_w && check_h && check_x && check_y)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int z = 0; z < n; z++) {
		int y, m, d, sum = 0;
		cin >> y >> m >> d;
		for (int i = 999; i > y; i--) {
			if (i % 3 == 0) sum += (20 * 10);
			else sum += (20 * 5 + 19 * 5);
		}
		for (int i = 10; i > m; i--) {
			if (y % 3 == 0) {
				sum += 20;
			}
			else {
				if (i % 2 == 0) sum += 19;
				else sum += 20;
			}
		}
		if (y % 3 == 0 || m % 2 == 1) sum += (20 - d);
		else sum += (19 - d);
		sum++;
		cout << sum << endl;
	}
}

Measured memory_bytes: 3040
s = input()
l = len(s)
ans = 0
for i in range(2**(l-1)):
    b = str(format(i, '0{}b'.format(l-1)))
    ns = ''
    for j in range(l):
        ns += s[j]
        if j!=l-1:
            if b[j]=='1':
                ns += '+'
    ans += eval(ns)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
//priority_queue<ll, vector<ll>, std::greater<ll> > q;
#define ull 		unsigned long long
#define ll 			long long
#define M 			1000000007
#define pb 			emplace_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define hell 		(ull)1e9
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define f1 first
#define s1 second
#define N 1005
using namespace std;
 
void boost()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

 
int main(void){
    boost();
    ll n;
    cin>>n;
    vi v(n);
    rep(i,0,n)
        cin>>v[i];
    ll a[n][n];
    rep(i,0,n)
        a[i][i] = v[i];
    ll j;
    for ( int d1 = 2 ; d1 <= n ; d1++){
        for ( int i = 0; i < n - d1 + 1; i++){
            j = i + d1 - 1;
            if (d1 == 2){
                a[i][j] = abs(v[i] - v[j]);
                //a[j][i] = abs(v[i] - v[j]);
            }
            else{
                a[i][j] = max(v[i] - a[i+1][j] , v[j] - a[i][j-1]); 
                //a[j][i] = max(v[i] - a[i+1][j] , v[j] - a[i][j-1]); 
            }
        }
    }
    cout<<a[0][n-1];
    // rep(i,0,n){
    //     rep(j,0,n)
    //         cout<<a[i][j]<<" ";
    //     cout<<"\n";
    // }
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

vector<int> split(const string& S, char delimiter)
{
  istringstream stream(S);
  string field;
  vector<int> result;
  while (getline(stream, field, delimiter)){
    result.push_back(atoi(field.c_str()));
  }
  return result;
}

class Solver {
public:
  Solver(vector<vector<int> >& tri) : tri(tri) {
    memset(memo, -1, sizeof(memo));
  }
  int get_max(int x, int y){
    if (y < 0 || y >= tri.size() || x < 0 || x >= tri[y].size()) return INT_MIN;
    if (memo[y][x] != -1) return memo[y][x];
    if (y == 0 && x == 0) return tri[0][0];
    if (y <= tri.size() / 2){
      return memo[y][x] = tri[y][x] + max(get_max(x - 1, y - 1), get_max(x, y - 1));
    }
    else {
      return memo[y][x] = tri[y][x] + max(get_max(x, y - 1), get_max(x + 1, y - 1));
    }
  }
  vector<vector<int> > tri;
  int memo[128][128];
};

int main()
{
  vector<vector<int> > tri;
  string line;
  while (getline(cin, line)){
    tri.push_back(split(line, ','));
  }
  Solver s(tri);
  printf("%d\n", s.get_max(0, tri.size() - 1));
  return 0;
}

Measured memory_bytes: 1344
# 083 B
N,A,B = map(int, input().split())
t = 0
for i in range(N):
    s =0
    n = i+1
    while n > 0:
        s += n%10
        n = int(n/10)
    if (s >= A)and(s <= B):
        t += (i+1)
print(t)

Measured memory_bytes: 67484
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
#include<climits>
#include<cfloat>
using namespace std;

int main(){
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	int count = 0;
	int ans;
	for(int i=0;i<n-1;i++){
		if(s.at(i) == s.at(i+1)){
			count++;
		}
	}
	ans = min(count+2*k,n-1);
	cout << ans << endl;
}

Measured memory_bytes: 512
import sys
from collections import defaultdict, deque
import math

# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7

def divide(k):
    return pow(k, MOD-2, MOD)


def make_nck(n):
    ret = [1]
    for i in range(1, n+1):
        ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)

    # print(ret)
    return ret

def make_nigojyo(n):
    ret = [1]

    for i in range(1, n+1):
        ret.append((ret[-1] * 25) % MOD)

    # print(ret)
    return ret


def solve():
    n = getN()
    a = getList()
    ans = 0
    for i, j in zip(a, a[1:]):
        ans += min(i, j)
    ans += a[0] + a[-1]

    print(ans)



def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 65588
#include <cstdio>
#include <vector>
#include <cstring>
#include <set>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> l4;
set<l4> xset, yset;
const int maxn = 1e5+1;
ll x[maxn], y[maxn], n;

struct Edge
{
    int u, v;
    ll len;
    bool operator<(const Edge &r) const
    {
        return len < r.len;
    }
};

int pa[maxn], cnt[maxn];
int init()
{
    for (int i = 1; i <= n; ++i)
    {
        pa[i] = i;
        cnt[i] = 1;
    }
}
int findpa(int id)
{
    return id==pa[id]?id:pa[id]=findpa(pa[id]);
}
bool merge(int x, int y)
{
    x = findpa(x);
    y = findpa(y);
    if (x != y)
    {
        if (cnt[x] > cnt[y])
            swap(x, y);
        pa[x] = y;
        cnt[y] += cnt[x];
        return true;
    }
    return false;
}
vector<Edge> e;

int main()
{
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld %lld", x+i, y+i);
        xset.insert(l4(x[i], i));
        yset.insert(l4(y[i], i));
    }
    for (int i = 1; i <= n; ++i)
    {
        set<l4>::iterator it = xset.find(l4(x[i], i));
        if (it != xset.begin())
        {
            --it;
            e.push_back((Edge){i, it->second, abs(x[i]-it->first)});
            ++it;
        }
        ++it;
        if (it != xset.end())
        {
            e.push_back((Edge){i, it->second, abs(x[i]-it->first)});
        }        
    }
    for (int i = 1; i <= n; ++i)
    {
        set<l4>::iterator it = yset.find(l4(y[i], i));
        if (it != yset.begin())
        {
            --it;
            e.push_back((Edge){i, it->second, abs(y[i]-it->first)});
            ++it;
        }
        ++it;
        if (it != yset.end())
        {
            e.push_back((Edge){i, it->second, abs(y[i]-it->first)});
        }        
    }
    sort(e.begin(), e.end());
    init();
    ll cost = 0;
    for (int i = 0; i < e.size(); ++i)
    {
        if (merge(e[i].u, e[i].v))
        {
            cost += e[i].len;
        }
    }
    printf("%lld\n", cost);
}

Measured memory_bytes: 24556
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 long double
#define pb                push_back
#define F                  first
#define S                  second
//#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  101LL
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll Powb(ll b,ll n,ll m);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l=0,r=0,a=0,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,flag=0;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> a >> b;
    if(a>9 or b>9) cout << -1;
    else cout << a*b;
}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    //memset(P,true,sizeof(P));
    //P[0] = false;
    //P[1]= false;
    for(int i=1;i<=n;i++) P[i] = i;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i]==i)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                if(P[j]==j)
                    P[j]=i;
            }
        }
    }

}



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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

void replace(string& str, const string& s1, const string& s2){
  int p = str.find(s1);
  while(p != string::npos){
	str.replace(p, SZ(s1), s2);
	p = str.find(s1, p+SZ(s2));
  }
}

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

  int N;
  while(cin>>N,N){
	vector<string> A(N), B(N);
	REP(i,N)
	  cin >> A[i] >> B[i];
	string S, T; cin >> S >> T;
	map<string, int> mp[2];
	int crt = 0, nxt = 1;
	mp[crt][S] = 0;
	bool update = true;
	while(update){
	  update = false;
	  mp[nxt] = mp[crt];
	  for(auto it=mp[crt].begin();it!=mp[crt].end();++it){
		REP(i,N){
		  string replaced = it->first;
		  replace(replaced, A[i], B[i]);
		  if(SZ(T) < SZ(replaced)) continue;
		  if(mp[nxt][replaced] == 0
			 || mp[nxt][replaced] > it->second + 1){
			update = true;
			mp[nxt][replaced] = it->second + 1;
		  }
		}
	  }
	  swap(crt, nxt);
	}
	if(S == T || mp[crt][T] > 0)
	  cout << mp[crt][T] << endl;
	else
	  cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 1564
import sys
N,M = map(int,input().split())
A = list(map(int,input().split()))
a = []
for i in A:
  i = i//2
  a.append(i)
def gcd(p,q):
  p,q = max(p,q),min(p,q)
  while q!=0:
    p,q = q,p%q
  return p
def lcm(p,q):
  return(p*q//gcd(p,q))
def aaa(i):
  count = 0
  while i%2==0:
    i = i//2
    count+=1
  return count
max_num = a[0]
aa = aaa(a[0])
for i in a:
  max_num = lcm(i,max_num)
  if aa != aaa(i):
    print(0)
    sys.exit()
print(((M//max_num)+1)//2)


Measured memory_bytes: 19796
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b;
            b = 100000;
            for (int i=0; i<a; i++){
                b *= 105;
                b /= 100;
                if (b%1000 != 0){
                    b -= b%1000;
                    b += 1000;
                }
            }
            System.out.println(b);
        }
    }
}


Measured memory_bytes: 26056
#include<cstdio>
const int MAXN=100;

char grid[MAXN+5][MAXN+5];

int main()
{
	int A,B,i,j;
	scanf("%d%d",&A,&B);
	for(i=0;i<MAXN/2;i++)
		for(j=0;j<MAXN;j++)
			grid[i][j]='.';
	for(int i=MAXN/2;i<MAXN;i++)
		for(j=0;j<MAXN;j++)
			grid[i][j]='#';
	A--;B--;
	for(i=MAXN-1;A;i-=2)
		for(j=0;j<MAXN&&A;j+=2)
			grid[i][j]='.',A--;
	for(i=0;B;i+=2)
		for(j=0;j<MAXN&&B;j+=2)
			grid[i][j]='#',B--;
	printf("%d %d\n",MAXN,MAXN);
	for(i=0;i<MAXN;i++)
		puts(grid[i]);
	return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):

    A = [0] + A + [0]
    cost = 0
    for i in range(1, len(A)):
        cost += abs(A[i]-A[i-1])

    for i in range(1,len(A)-1):
        if((A[i-1] <= A[i] <= A[i+1]) or (A[i-1] >= A[i] >= A[i+1])):
            print(cost)
        else:
            print(cost-2*min(abs(A[i+1]-A[i]),abs(A[i]-A[i-1])))


    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15684
import collections
S=input()
T=input()
a1=collections.Counter(S)
a2=collections.Counter(T)
x=''
for i in range(len(S)):
    if a1[S[i]]!=a2[T[i]]:
        x='No'
if x=='':
    print('Yes')
else:
    print(x)

Measured memory_bytes: 4144
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
vector<ll> adj[100001];
ll dp[100001][2], mod = 1e9 + 7;
ll ans(ll v, ll color, ll parent) {
	// cout<<v<<" "<<color<<" "<<parent<<"\n";
	if(dp[v][color] != -1) {
		return dp[v][color];
	}
	ll flag = 1, ret = 1, cur;
	for(auto u: adj[v]) {
		if(u != parent) {
			flag = 0;
			cur = 0;
			cur = (cur + ans(u, 0, v))%mod;
			if(color == 0) {
				cur = (cur + ans(u, 1, v))%mod;
			}
			ret = (ret * cur)%mod;
		}
	}
	return dp[v][color] = ret;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    for(int i = 0; i <= n; i++) {
    	dp[i][0] = dp[i][1] = -1;
    }
    for(int i = 0; i < n - 1; i++) {
    	int x, y;
    	cin>>x>>y;
    	adj[x].pb(y);
    	adj[y].pb(x);
    }
    cout<< ( ans(1, 0, 1) + ans(1, 1, 1) )%mod << "\n";
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, int> P;

int main() {
  int n;
  while (cin >> n, n) {
    cin.ignore();
    vector<string> v;
    map<string, int> mp;
    while (n--) {
      string line;
      getline(cin, line);
      istringstream iss(line);
      string s;
      while (iss >> s) {
        v.push_back(s);
      }
    }
    char k;
    cin >> k;
    for (const auto& e : v) {
      if (e[0] == k) mp[e]++;
    }
    vector<P> u;
    for (const auto& e : mp) {
      u.push_back(e);
    }
    sort(u.begin(), u.end(), [](auto const& x, auto const& y) {
      if (x.second != y.second) return x.second > y.second;
      return x.first < y.first;
    });
    if (u.empty()) {
      cout << "NA\n";
    } else {
      for (int i = 0; i < u.size() && i < 5; i++) {
        cout << (i == 0 ? "" : " ") << u[i].first;
      }
      cout << "\n";
    }
  }
}



Measured memory_bytes: 3164
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  whilwee(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組fみ合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat

////////////// BubbleSort(A,N) ///////////////

int main (){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }

    int i = 0; // 先頭インデックス
    int cou = 0;
    int flag = 1;
    for(i=0;flag;i++){
        while(flag){
            flag = 0;
            for(int j=n-1;j>=i+1;j--){
                if(a[j-1]>a[j]){
                    int t = a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    cou++;
                    flag = 1;
                }
            }
        }
    }
    REP(i,n-1){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    cout << cou << endl;
   
}


Measured memory_bytes: 3080