akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>


using namespace std;


using ll = long long;

ll N;
vector<vector<pair<ll, ll>>> graph;
vector<bool> discovered;
vector<pair<ll, ll>> edges;
vector<ll> parent_color;


void dfs(ll start) {
    stack<ll> s;
    s.push(start);
    discovered[start] = true;

    while (!s.empty()) {
        ll now = s.top();
        s.pop();

        ll chosen = 1;
        for (auto &e : graph[now]) {
            if (discovered[e.first])
                continue;
            if (parent_color[now] == chosen)
                chosen++;

            e.second = chosen;
            parent_color[e.first] = chosen++;

            discovered[e.first] = true;
            s.push(e.first);
        }
    }
}


int main() {
    cin >> N;
    graph.resize(N + 1);
    discovered.resize(N + 1, false);
    parent_color.resize(N + 1, 0);

    for (ll i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        graph[a].push_back(make_pair(b, 0));
        graph[b].push_back(make_pair(a, 0));
        edges.push_back(make_pair(a, b));
    }

    for (ll i = 0; i < N; i++) {
        sort(graph[i].begin(), graph[i].end(), [](auto l, auto r) { return l.first < r.first; });
    }

    ll start;
    ll K = 0;
    for (ll i = 0; i < N; i++) {
        if (K < graph[i].size()) {
            K = graph[i].size();
            start = i;
        }
    }

    dfs(start);

    cout << K << endl;
    for (auto e : edges) {
        auto a = find_if(graph[e.first].begin(), graph[e.first].end(), 
                    [=](pair<ll, ll> x) { return e.second == x.first; });
        auto b = find_if(graph[e.second].begin(), graph[e.second].end(),
                    [=](pair<ll, ll> x) { return e.first == x.first; });
        if (a->second != 0) {
            cout << a->second << endl;
        } else {
            cout << b->second << endl;
        }
    }
}


Measured memory_bytes: 10224
import sys
def input():
	return sys.stdin.readline()[:-1]
n, m, q = map(int, input().split())
reqs = [list(map(int, input().split())) for _ in range(q)]

ans = 0
for i in range(1<<(n+m-1)):
	if bin(i).count("1") != n:
		continue
	l = []
	tmp = 1
	for j in range(n+m-1):
		if (i>>j) & 1:
			l.append(tmp)
		else:
			tmp += 1
	res = 0
	for a, b, c, d in reqs:
		if l[b-1] - l[a-1] == c:
			res += d
	ans = max(ans, res)
print(ans)

Measured memory_bytes: 68804
X,K,D = map(int, input().split())
ans = 0
if K < abs(X)//D:
  ans = abs(X) - D*K
else:
  if ((K-X//D)%2 == 0):
    ans = abs(X%D)
  else:
    ans = abs(abs(X%D) - D)
print(ans)

Measured memory_bytes: 61576
fn main() {
  let (a, p) = {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut ws = s.split_whitespace();
    let a: i64 = ws.next().unwrap().parse().unwrap();
    let b: i64 = ws.next().unwrap().parse().unwrap();
    (a, b)
  };

  print!("{}", (a * 3 + p) / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int N, K, a[100001], d[100001], c[100001];
vector<int> G[100001];

void dfs(int u) {
    for (int v : G[u]) {
        dfs(v);
        d[u] = max(d[v]+1, d[u]);
        c[u] += c[v];
    }
    if (u > 1 && a[u] > 1 && d[u] == K-1) {
        d[u] = -1;
        ++c[u];
    }
}

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    cin >> N >> K;
    for (int u = 1; u <= N; ++u) {
        cin >> a[u];
        if (u > 1) G[a[u]].push_back(u);
    }
    dfs(1);
    cout << (a[1] > 1) + c[1];
}

Measured memory_bytes: 18104
x, k, d = input().strip().split(' ')
x = int(x)
k = int(k)
d = int(d)

l, r, d1 = -k, k, k + 1
while (l <= r):
    mid = (l + r) // 2
    if (x + mid * d >= 0):
        d1 = mid 
        r = mid - 1
    else:
        l = mid + 1

l, r, d2 = -k, k, k + 1
while (l <= r):
    mid = (l + r) // 2
    if (x - mid * d < 0):
        d2 = mid 
        l = mid + 1
    else:
        r = mid - 1

ans = int(1e30)
if (d1 != k + 1):
    r = (k - abs(d1)) % 2
    if (r == 0):
        ans = min(ans, abs(x + d * (d1 + r)))
    else:
        ans = min(ans, abs(x + d * (d1 - 1)))
        ans = min(ans, abs(x + d * (d1 + 1)))
if (d2 != k + 1):
    r = (k - abs(d2)) % 2
    if (r == 0):
        ans = min(ans, abs(x + d * (d2 + r)))
    else:
        ans = min(ans, abs(x + d * (d2 - 1)))
        ans = min(ans, abs(x + d * (d2 + 1)))


print(ans)

Measured memory_bytes: 9300
n = int(input())
li = list(map(int,input().split()))

li.sort()

ans = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if li[i] != li[j] != li[k]:
                if li[i] + li[j] > li[k]:
                    ans += 1
print(ans)


Measured memory_bytes: 9096
package main

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

func main() {
	run()
}

func run() {
	setSpace()
	n := readN()
	as := make([]int, n)
	bs := make([]int, n)
	cs := make([]int, n)
	for i := 0; i < n; i++ {
		as[i], bs[i], cs[i] = readN(), readN(), readN()
	}

	dp := make([][]int, n)
	dp[0] = []int{as[0], bs[0], cs[0]}

	for i := 1; i < n; i++ {
		prevA, prevB, prevC := dp[i-1][0], dp[i-1][1], dp[i-1][2]
		dp[i] = []int{0, 0, 0}
		// if A was selected previous,
		chMax(&dp[i][1], prevA+bs[i])
		chMax(&dp[i][2], prevA+cs[i])

		// if B was selected previous,
		chMax(&dp[i][0], prevB+as[i])
		chMax(&dp[i][2], prevB+cs[i])

		// if C was selected previous
		chMax(&dp[i][0], prevC+as[i])
		chMax(&dp[i][1], prevC+bs[i])

		// assign to #i
	}

	fmt.Println(max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]))
}

func chMax(a *int, b int) {
	if *a > b {
		return
	}
	*a = b
}

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

// ------以下、ユーティリティ------

var sc = bufio.NewScanner(os.Stdin)

func setSpace() {
	sc.Split(bufio.ScanWords)
}

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

func readN() int {
	n, err := strconv.Atoi(read())
	if err != nil {
		panic(err)
	}
	return n
}


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

int main()
{
  string S;
  cin >> S;
  
  string comp = "CODEFESTIVAL2016";
  int count = 0;
  for(int i = 0; i < 16; i++)
  {
    if(S.at(i) != comp.at(i))
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int32_t, int32_t> pii;
typedef vector<int32_t> vi;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;

  string a, b;
  cin >> a >> b;

  int32_t dp[a.length() + 1][b.length() + 1];
  rep(i, max(a.length() + 1, b.length() + 1)) {
    if (i <= a.length()) dp[i][0] = 0;
    if (i <= b.length()) dp[0][i] = 0;
  }

  rep(i, a.length()) {
    rep(j, b.length()) {
      dp[i + 1][j + 1] =
          a[i] == b[j] ? dp[i][j] + 1 : max(dp[i + 1][j], dp[i][j + 1]);
      // cerr << dp[i + 1][j + 1] << ':' << a[i] << ':' << b[j] << ' ';
    }
    // cerr << '\n';
  }

  string res;

  int32_t current = dp[a.length()][b.length()];
  int32_t i = a.length(), j = b.length();
  while (current != 0) {
    while (current == dp[i][j - 1]) j--;
    while (current == dp[i - 1][j]) i--;
    res += a[i - 1];
    current = dp[i - 1][j - 1];
    i--;
    j--;
  }
  reverse(res.begin(), res.end());
  cout << res;
}

Measured memory_bytes: 35456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		for (int i = 0; i < String.valueOf(b).length(); i++) {
			a *= 10;
		}

		int c = a + b;

		if ((int) Math.sqrt(c) * (int) Math.sqrt(c) == c) {
			System.out.println("Yes");
		} else {

			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\n'
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007

int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  char x;
  cin >> x;
  if (x >= 'a')
    cout << "a";
  else
    cout << "A";
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int H;
void maxHeap(int *A,int i){
  int l,r;
  int tmp;
  int largest;
  l=i*2;
  r=i*2+1;
  
  if(l<=H && A[l] > A[i])
    largest = l;
  else largest = i;

  if(r<=H && A[r] > A[largest])
    largest = r;

  if(largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeap(A,largest);
  }
}

void buildmaxHeap(int *A){
  int i;
  for(i=H/2;i>=1;i--)maxHeap(A,i);
}
int main(){
  int i;
  int A[500001];
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);
  buildmaxHeap(A);
  for(i=1;i<=H;i++)printf(" %d",A[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 2552
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    ULL N;
    ULL num_of_two;
    ULL num_of_five;
    ULL div_of_two;
    ULL div_of_five;
    ULL two,five;
    ULL start;
    ULL i,j;
    cin >> N;

    num_of_two =0;
    num_of_five = 0;
    if( N % 2 == 0){
        two = 2;
        while( N >= two){
            num_of_two += N / two;
            two *= 2;   
        }
        five = 10;
        while(N >= five){
            num_of_five += N / five;
            five *= 5;
        }
        //cout << num_of_two << "," << num_of_five << endl;
        if( num_of_two > num_of_five){
            cout << num_of_five << endl;
        }else{
            cout << num_of_two << endl;
        }
    }else{
        cout << 0 << endl;
    }
}

void process(){
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int price,sum,num;
    scanf("%d%d%d",&price,&sum,&num);
    int num1=sum/price;
    if(num1>num){
        printf("%d\n",num);
    }
    else{
        printf("%d\n",num1);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


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

    list<char>l;


    ll q,i,j;

    for(i=0;i<s.length();i++)
    {
        l.pb(s[i]);
    }

    cin>>q;
    ll a,b;
    char c;
    ll ct=0;
    while(q--)
    {
        cin>>a;
        if(a==1)
        {
            ct++;
        }
        else if(a==2)
        {
            cin>>b>>c;
            if(b==1)
            {
                if(ct%2==0)
                {
                    l.pf(c);
                }
                else
                {
                    l.pb(c);
                }
            }
            else
            {
                if(ct%2==0)
                {
                    l.pb(c);
                }
                else
                {
                    l.pf(c);
                }
            }
        }
    }

    if(ct%2==0)
    {
        for(auto it=l.begin(); it!=l.end() ; it++)
        {
            cout<<*it;
        }
    }
    else
    {
        for(auto it=l.rbegin(); it!=l.rend() ; it++)
        {
            cout<<*it;
        }
    }
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

int main() {
    int n;
    cin >> n;
    int* a = new int[n];
    rep(i, n) cin >> a[i];
    int* b = new int[n];
    rep(i, n) cin >> b[i];
    int* c = new int[n - 1];
    rep(i, n - 1) cin >> c[i];
    int before = -2;
    int ans = 0;
    rep(i, n) {
        if(before + 1 == a[i] - 1) ans += c[before];
        ans += b[a[i] - 1];
        before = a[i] - 1;
    }
    cout << ans << endl;
}


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

int main() {
  int n,q; string s;
  cin >> n >> q >> s;
  vector<int> a(n+1,0);
  rep(i,1,n+1) {
    if (s.substr(i-1,2) == "AC") {
      a[i]++;
    }
    a[i] += a[i-1];
  }
  rep(i,0,q) {
    int l,r;
    cin >> l >> r;
    int ans = a[r] - a[l];
    if (a[l] != a[l-1]) ans++;
    if (a[r] != a[r-1]) ans--;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3828
function main(input) {
    const args = input.split('\n');
    const N = parseInt(args[0], 10);
    var A = args[1].toString();
    var B = args[2].toString();
    var C = args[3].toString();

    var ans_change = 0;

    for(var i=0; i < N; i++) {
        if (A.charAt(i) === B.charAt(i) && A.charAt(i) === C.charAt(i)) {

        } else if (A.charAt(i) === B.charAt(i) || A.charAt(i) === C.charAt(i) || B.charAt(i) === C.charAt(i)) {
            ans_change += 1;
        } else {
            ans_change += 2;
        }
    }

    console.log(ans_change);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
n = list(map(int, input().split()))
n = n[0]
xy=[]
for i in range(n):
    x,y = list(map(int, input().split()))
    xy.append([x,y])

distlist=[]
distnum=[]

for i in range(n):
    for j in range(n):
        vec=[xy[i][0]-xy[j][0], xy[i][1]-xy[j][1]]
        if(i==j):
             continue
        flag=0
        for k in range(len(distlist)):
            if(distlist[k][0]==vec[0] and distlist[k][1]==vec[1]):
                distnum[k] += 1
                flag=1
                break
        if(flag==0):
            distlist.append(vec)
            distnum.append(1)

if(n==1):
    print(1)
else:
    print(max(n-max(distnum),1))


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

int main(void){
    int n, k;
    cin >> n >> k;

    vector<vector<int>> black, white;
    black = vector<vector<int>>(k+2, vector<int>(k+2, 0));
    white = vector<vector<int>>(k+2, vector<int>(k+2, 0));

    for(int i=0; i<n; i++){
        int x, y;
        char c;
        cin >> x >> y >> c;
        if((x/k+y/k)%2 == 1){
            if(c == 'W'){
                c = 'B';
            }else{
                c = 'W';
            }
        }
        if(c == 'B'){
            black[x%k+1][y%k+1]++;
        }else{
            white[x%k+1][y%k+1]++;
        }
    }

    vector<vector<int>> bsum, wsum;
    bsum = vector<vector<int>>(k+2, vector<int>(k+2, 0));
    wsum = vector<vector<int>>(k+2, vector<int>(k+2, 0));

    for(int i=1; i<=k+1; i++){
        for(int j=1; j<=k+1; j++){
            bsum[i][j] = black[i][j] + bsum[i-1][j] + bsum[i][j-1] - bsum[i-1][j-1];
            wsum[i][j] = white[i][j] + wsum[i-1][j] + wsum[i][j-1] - wsum[i-1][j-1];
        }
    } 

    int ans = 0;

    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            int cnt1 = bsum[k+1][k+1] - bsum[i][k+1] - bsum[k+1][j] + 2*bsum[i][j];
            cnt1 += wsum[i][k+1] + wsum[k+1][j] - 2*wsum[i][j];
            int cnt2 = wsum[k+1][k+1] - wsum[i][k+1] - wsum[k+1][j] + 2*wsum[i][j];
            cnt2 += bsum[i][k+1] + bsum[k+1][j] - 2*bsum[i][j];
            ans = max({ans, cnt1, cnt2});
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>//万能头 
using namespace std;
int a[10000001];//注意数组开大点，坑了我几个点 
inline int read(){//快速读入，比scanf和cin都要快 
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(int x){//快写，比cout和printf也要快 
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
int main(){
    int n=read()/*读入n*/,s=0;
    for(int i=1;i<=n;i++){
        a[i]=i;//将i储存在a数组中 
        s+=i;//将1~n加起来 
        if(s>n)//如果和大于n，就代表要找的数字已经到齐了 ，break 
        break;
    }
    int t=s-n;//将和与n的差算出 
    for(int i=1;i<=n;i++){
        if(a[i]){//以防没有读入的数组变量，相当于a[i]!=0 
            if(a[i]!=t){//在a数组中将t删去  ，剩下的数的和刚好等于n 
                write(a[i]);//输出 
                printf("\n");//AT的题要换行 
            }
        }
    }
    return 0;//养成好习惯 
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int n, a;
    cin >> n >> a;

    cout << n * n - a << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
long long a[200010], b[200010];
int n;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	if (n % 2) {
		cout << b[n / 2 + 1] - a[n / 2 + 1] + 1;
	} else {
		cout << b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1; 
	}
	return 0;
}

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

typedef struct node{
  int key;
  struct node *next, *prev;
}Node;

Node *nil;

Node* listsearch(int key){
  Node *cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printlist(){
  Node *cur = nil->next;
  int m = 0;
  while(1){
    if(cur == nil) break;
    if(m++ > 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listsearch(key));
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int n, i, key;
  char str[20];

  scanf("%d", &n);
  init();
  for(i=0; i<n; i++){
    scanf("%s%d", str, &key);
    if(str[0] == 'i') insert(key);
    else if(str[0] == 'd'){
      if(strlen(str) > 6){
        if(str[6] == 'F') deleteFirst();
        else if(str[6] == 'L') deleteLast();
      } else {
        deleteKey(key);                                                                          
      }                                                                        
    }
  }

  printlist();

  return 0;
}

Measured memory_bytes: 31788
#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<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int s;
    cin >> s;
    vector<int> id(1e6, -1);
    int len = 1;
    while (id[s] == -1) {
        len++;
        id[s] = len;
        if (s%2 == 0) s /= 2;
        else s = 3*s+1;
    }
    cout << len << endl;
    return 0;
}

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

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

	if(n==1)
	{
		cout<<"Yes"<<endl;
		cout<<"2"<<endl;
		cout<<"1 1"<<endl;
		cout<<"1 1"<<endl;
		return 0;
	}
	for(int i = 1;i < 1000;i++)
	{
		//cout<<i*(i+1)<<endl;
		if(n*2==i*(i+1))
		{
			vector<vector<int>> a(i+1,vector<int>(i));
			int now = 1;
			for(int j = 0;j<i;j++)
			{
				for(int k = j;k<i;k++)
				{
					a[j][k] = now;
					a[k+1][j] = now++;
				}
			}
			cout<<"Yes"<<endl;
			cout<<a.size()<<endl;
			for(auto j:a)
			{
				cout<<j.size()<<' ';
				for(auto k:j)
				{
					cout<<k<<' ';
				}
				cout<<endl;
			}
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 2176
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

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

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

string target = "keyence";

int main() {
	string s;
	cin >> s;
	if (s == target) {
		cout << "YES" << endl;
		return 0; 
	}
	
	int n = s.size();
	for(int i = 0; i < n; i++){
		for(int j = i; j < n; j++) {
			string S = "";
			for(int k = 0; k < n; k++){
				if(i<=k && k<=j){
					continue;
				}
				else S.push_back(s[k]);
			}
			if(S == target){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
cnt = 0
indL = -1
for i in range(indL+1,N):
    if H[indL+1]==0:
        indL += 1
        continue
    else:break
while indL<N-1:
    hmin = 1000
    indR = N
    for i in range(indL+1,N):
        if H[i]==0:
            indR = i
            break
        else:
            hmin = min(hmin,H[i])
    for i in range(indL+1,indR):
        H[i] -= hmin
    cnt += hmin
    for i in range(indL+1,N):
        if H[indL+1]==0:
            indL += 1
            continue
        else:break
print(cnt)   

Measured memory_bytes: 38768
// Hacheylight
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
//#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 200010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
template <class T> void print(T a) { cout << a << endl ; exit(0) ; }
template <class T> void chmin(T &a, T b) { if (a > b) a = b ; }
template <class T> void chmax(T &a, T b) { if (a < b) a = b ; }
template <class T> void add(T &a, T b) { a = (1ll * a + b) % MOD ; }
template <class T> void mul(T &a, T b) { a = (ll) a * b % MOD ; }
template <class T> T read() {
    int f = 1 ; T x = 0 ;
    char ch = getchar() ;
    while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
    while (isdigit(ch)) { x = x * 10 + ch -'0' ; ch = getchar() ; }
    return x * f ;
}

 // pair <从端点开始的顶点的个数, 端点>


vi g[N] ;
int n ;


pii dfs(int x, int fat) {
	pii ans = mp(0, x) ;
	for (int to : g[x]) {
		if (to == fat) continue ;
		chmax(ans, dfs(to, x)) ;
	}
	ans.fi++ ;
	return ans ;
}

signed main() {
	scanf("%d", &n) ;
	rep(i, 1, n - 1) {
		int a, b ; scanf("%d%d", &a, &b) ;
		g[a].pb(b) ; g[b].pb(a) ;
	}
	int dia = dfs(dfs(1, -1).se, -1).fi ;
	puts((dia % 3 != 2) ? "First" : "Second") ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
	6.逆向思维？
*/





Measured memory_bytes: 23680
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    x = list(range(1, n+1))
    p = Input()
    data = [i != j for i, j in zip(x, p)]
    if sum(data) > 2:
        print("NO")
    else:
        print("YES")

main()

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
int main(){
	double x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	cout<<fixed<<setprecision(8)<<sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	return 0;
}



Measured memory_bytes: 3200
#!/usr/bin/env python3
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def dfs(now):
    seen[now] = True
    score[now] += operation[now]
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
operation = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    operation[p - 1] += x

seen = [False] * N
score = [0] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

for ans in score:
    print(ans, end=' ')


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

int main() {
  int n; cin >>n;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
  sort(a.rbegin(),a.rend());
  cout<<a[0].first+a[0].second<<endl;
  return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int a[maxn],b[maxn];
int main()
{
	int n;cin>>n;cin>>a[1];
	int ans=0;ans+=a[1];
	for(int i=2;i<n;i++)
	{
		cin>>a[i];
		ans+=min(a[i],a[i-1]);
	}
	ans+=a[n-1];
	cout<<ans<<endl;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define END(a) {cout << (a) << "\n"; return 0;}
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
const long double pi = acos(-1);
int main() {
    init();
    
    double a, b, x; cin >> a >> b >> x;
    double Max = a * a * b;

    if (Max / 2 == x) {
        cout << "45\n";
    }
    else if (Max / 2 < x) {
        double ng = b, ok = 0;
        double lim = Max - x;
        FOR(cnt, 0, 1000000) {
            double mid = (ok + ng) / 2;
            if (a * a * mid / 2 > lim)ng = mid;
            else ok = mid;
        }
        cout << atan(ok / a) / pi * 180;
    }
    else {
        long double ng = a, ok = 0;
        FOR(cnt, 0, 1000000) {
            long double mid = (ok + ng) / 2;
            if (a * b * mid / 2 > x)ng = mid;
            else ok = mid;
        }
        cout << ((pi / 2) - atan(ok / b)) / pi * 180;
    }
}

Measured memory_bytes: 384
var a1,a2,b1,b2:longint;
begin
readln(a1,a2,b1,b2);
if A1+A2>B1+B2 then
writeln('Left');
if A1+A2=B1+B2 then
writeln('Balanced');
if A1+A2<B1+B2 then
writeln('Right');
end.

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
using ll = long long;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<pair<ll, int>>> edge(n);
    for (int i = 1; i < n; i++) {
        edge[i].emplace_back(0, i-1);
    }
    
    for (int i = 0; i < m; i++)
    {
        ll l, r, c; cin >> l >> r >> c;
        l--; r--;
        edge[l].emplace_back(c, r);
    }
    
    ll inf = 1e14;
    vector<ll> dist(n, inf);
    auto djk = [&]() -> void {
        dist[0] = 0;
        using P = pair<ll, int>;
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.push(P(0, 0));
        while (!pq.empty()) {
            P p = pq.top();
            pq.pop();
            int v = p.second;
            if (p.first > dist[v]) continue;

            for (int i = 0; i < edge[v].size(); i++) {
                int next = edge[v][i].second;
                ll cost = edge[v][i].first;
                if (dist[next] > dist[v] + cost) {
                    dist[next] = dist[v] + cost;
                    pq.push(P(dist[next], next));
                }
            }
        }
    };
    djk();

    if (dist[n-1] == inf) cout << -1 << endl;
    else cout << dist[n-1] << endl;
    return 0;
}

Measured memory_bytes: 10104
ans_list = []

while True:
    b = int(input())
    if b == 0:
        break
    h = 1
    ans = -1
    while h*(h-1)//2 <= b:
        if (b- h*(h-1)//2) % h == 0:
            n = (b- h*(h-1)//2) // h
            if n >= 1:
                ans = "{} {}".format(n, h)
        h += 1

    ans_list.append(ans)

for ans in ans_list:
    print(ans)


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

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

#define Debug(x) cout<<(#x)<<" >> "<<(x)<<endl

using namespace std;

ll fastpow(ll angka,ll pangkat,ll MOD){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka)%MOD;
		angka=(angka*angka)%MOD;
		pangkat=pangkat>>1;
	}
	return res;
}

ll fastpow(ll angka,ll pangkat){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka);
		angka=(angka*angka);
		pangkat=pangkat>>1;
	}
	return res;
}

ll gcd(ll angka1,ll angka2){
	while(angka2){
		swap(angka1,angka2);
		angka2=angka2%angka1;
	}
	return angka1;
}

ll lcm(ll angka1,ll angka2){
	return (angka1/gcd(angka1,angka2))*angka2;
}




void solve(){
	ll a,b,c;
	ll k;
	
	cin>>a>>b>>c>>k;
	
	while(k>0){
		if(b<=a){
			b=b*2;
			k--;
		}
		else if(c<=b){
			c=c*2;
			k--;
		}
		else break;
	}
	
	if(a<b && b<c) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

int main(){
	
	fastio();

	int t=1;
//	cin>>t;
	
	for(int tt=0;tt<t;tt++){
//		cout<<"Case #"<<tt+1<<": ";solve();
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
	int K;
	string S;
	cin>>K>>S;
	if(S.size()<=K)cout<<S<<endl;
	else{
		rep(i,K){
			cout<<S.at(i);
		}
		cout<<"..."<<endl;
	}
}

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

using namespace std;

const uint64_t Undedined =static_cast<uint64_t>(-1);

typedef std::vector<std::map<uint64_t, uint64_t>> SparseEdge;

// ワーシャル・フロイド法
vector<vector<uint64_t>> warshall_floyd(uint64_t N, SparseEdge &edges)
{
  vector<vector<uint64_t>> d(N, vector<uint64_t>(N, Undedined));
  
  for (uint64_t i = 0; i < N; ++i) {
    for (auto &p : edges[i]) {
      d[i][p.first] = p.second;
    }
    d[i][i] = 0;
  }
  
  for (uint64_t i = 0; i < N; ++i) {
    for (uint64_t j = 0; j < N; ++j) {
      for (uint64_t k = 0; k < N; ++k) {
        if (d[j][i] == Undedined || d[i][k] == Undedined) { continue; }
        if (d[j][k] > d[j][i] + d[i][k]) {
          d[j][k] = d[j][i] + d[i][k];
        }
      }
    }
  }
  
  return d;
}

int main()
{
  uint64_t N, M, L;
  cin >> N >> M >> L;
  
  SparseEdge distance_edges(N);
  for (uint64_t m = 0; m < M; ++m) {
    uint64_t A, B, C;
    cin >> A >> B >> C;
    
    // タンクの容量を超える道はそもそも通れない
    if (C <= L) {
      distance_edges[A - 1].emplace(B - 1, C);
      distance_edges[B - 1].emplace(A - 1, C);
    }
  }
  
  vector<vector<uint64_t>> d1 = warshall_floyd(N, distance_edges);
  
  SparseEdge refueling_edges(N);
  for (uint64_t i = 0; i < N; ++i) {
    for (uint64_t j = 0; j < N; ++j) {
      if (i != j && d1[i][j] <= L) {
        refueling_edges[i].emplace(j, 1);
      }
    }
  }
  
  vector<vector<uint64_t>> d2 = warshall_floyd(N, refueling_edges);
  
  uint64_t Q;
  cin >> Q;
  
  for (uint64_t q = 0; q < Q; ++q) {
    uint64_t s, t;
    cin >> s >> t;
    --s; --t;
    
    if (d2[s][t] == Undedined) {
      cout << -1 << endl;
    } else {
      cout << (d2[s][t] - 1) << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 13056
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long ans = a.back();
  a.pop_back();
  sort(a.rbegin(), a.rend());
  int k = n - 2;
  int i = 0;
  while (k > 0) {
    ans += a[i];
    k--;
    if (k <= 0) break;
    ans += a[i];
    k--;
    i++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4004
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
syaku = 0
for i in range(n-1):
  if a[i]+a[i+1]>=x:
    sa=a[i]+a[i+1]-x
    ans+=sa
    if sa<=a[i+1]:
      a[i+1]-=sa
    else:
      a[i]=sa-a[i+1]
      a[i+1]=0

if n!=2 and a[n-2]+a[n-1]>=x:
  sa=a[i]+a[i+1]-x
  ans+=sa
  if sa<=a[n-1]:
    a[n-1]-=sa
  else:
    a[n-2]=sa-a[n-1]
    a[n-1]=0
print(ans)

Measured memory_bytes: 20132
#include <stdio.h>

int main(void)
 {
  int x,y,z;
  double b;
  
  scanf("%d%d%d",&x,&y,&z);
  
  if(x%(y+z)==z) printf("%d\n",x/(y+z));
  else           printf("%d\n",(x/(y+z))-1);

  return 0;
}

Measured memory_bytes: 128
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, k = gsmi
x = gsmi

prev = x[k-1]-x[0]
min = prev + min(x[0].abs, x[k-1].abs)

1.upto(n-k) do |i|
  dist1 = prev-(x[i]-x[i-1])+(x[i+k-1]-x[i+k-2])
  dist = dist1 + min(x[i].abs, x[i+k-1].abs)
  #debug 'dist',dist
  #debug 'dist1',dist1
  min = dist if min>dist
  prev = dist1
end

puts min

Measured memory_bytes: 9492
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (a % b == 0)
		return b;
	else
	{
		return gcd(b, a % b);
	}
}
ll x[11];
void solve()
{
	ll r, d;
	cin >> r >> d >> x[0];
	for (int i = 1; i <= 10; i++)
	{
		x[i] = r * x[i - 1] - d;
		cout << x[i] << endl;
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}

Measured memory_bytes: 256
import re
array = []
lines = []
count = 0
while True:
    n = input()
    if n == "-":
        break
    array.append(n)
for i in range(len(array)):
    if re.compile("[a-z]").search(array[i]):
        fuck = i+1
        if count > 0:
            lines.append(stt)
        count += 1
        stt = array[i]
    else:
        if i == fuck:
            continue
        stt = stt[int(array[i]):len(stt)]+stt[0:int(array[i])]
        if i == len(array)-1:
            lines.append(stt)
for i in range(len(lines)):
    print(lines[i])

Measured memory_bytes: 7848
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const input = (lines[0] as string).split(" ");
  const hNum = Number(input[0]);
  const wNum = Number(input[1]);

  console.log(wNum >= hNum ? "unsafe" : "safe");
});


Measured memory_bytes: 30072
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
map<char,int>no;
int func(string s){
  int sum=0;
  rep(i,s.size()){
    if(isalpha(s[i]))sum+=no[s[i]];
    else sum+=(s[i]-'0')*no[s[++i]];
  }
  return sum;
}
string func1(int sum){
  string s="";
  string  in[4]={"i","x","c","m"};
  int co=0;
  while(sum){
    int a=sum%10;
    if(a)s=in[co]+s;
    if(a>1)s=(char)(a+'0')+s;
    co++;
    sum/=10;
  }
  return s;
}
int main(){
  no['m']=1000;
  no['c']=100;
  no['x']=10;
  no['i']=1;

  int n;
  cin>>n;
  while(n--){
    string a,b;
    cin>>a>>b;
    int sum=func(a)+func(b);
    //cout<<func(a)<<" "<<func(b)<<endl;;
    cout<<func1(sum)<<endl;
  }
}

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

/*
　+を挿入した後、その位置で分割して足していく
*/

int main(){
    string S;
    cin >> S;
    long long int answer = 0;
    string tmp,tmp2="";

    for(int bit=0;bit<(1<<( S.size()-1 ));bit++){ //+を全ての場所について入れるか入れないかで2^(N-1)通り。bit全探索
        tmp = S[0];
        for(int i=0;i<(S.size()-1);i++){ //iは+の個数　最大で文字数-1個
            if(bit & (1<<i)){ 
                tmp += '+'; //S[i]の次に+を挿入すると考える
            }
            tmp += S[i+1];
        }
        //cout << tmp << endl;
        for(int i=0;i<tmp.size();i++){
            if(tmp[i]!='+'){
                tmp2 += tmp[i];
                //cout << tmp2 << endl;
            }else{
                answer += stoll(tmp2);
                tmp2 = "";
            }
            if(i == tmp.size()-1){
                answer += stoll(tmp2);
                tmp2 = "";
            }
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++)
	for(ll j=i;j<=n;j=j+i)
	sum+=j;
	cout<<sum;
	return 0;
}

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

    #define all(v) v.begin(),v.end()
    #define rall(v) v.rbegin(),v.rend()
    #define trav(i,a) for(auto i: a)
    #define ff first
    #define ss second
    #define pb push_back
    #define tc(t) ll t; cin>>t; while(t--)
    #define prec(n) fixed<<setprecision(n)
    #define mst(arr,value) memset(arr,value,sizeof(arr))
    #define sz(a) a.size()
    #define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    
    const long long inf = (long long)1e18;
    const long long M = (long long)1e9+7;
    
    #define fab(i,a,b) for(ll i=a; i<b; i++)
    #define fba(i,b,a) for(ll i=b; i>=a; i--)

    ll mpw(ll a, ll b, ll M = inf) {
        if(b == 0) return 1;
        if(b % 2 == 1) 
            return a * mpw((a * a) % M, b / 2, M) % M;
        return mpw((a * a) % M, b / 2, M);        
    }    

    int main() {
        fio


        ll n, k;
        cin >> n >> k;
        vector<ll> v(n), dp(n, inf);
        fab(i, 0, n) cin >> v[i];
        dp[0] = 0;
        fab(i, 1, n) {
            fab(j, 1, min(i, k) + 1) {
                dp[i] = min(dp[i - j] + abs(v[i] - v[i - j]), dp[i]);
            }
        }
        cout << dp[n - 1];
        return 0;
    }

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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if (A+B>C+D) {
    cout<<"Left"<<endl;
  }
  else if (A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  else {
    cout<<"Right"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n, d;
  cin >> n >> d;
  int x[n*d];
  //printf("%d %d\n", n, d);
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < d; ++j){
       cin >> x[i*d + j];
      //printf("%d\n", x[i*d+j]);
    }
  }
  //printf("%d %d\n", n, d);
  //printf("confirm\n");

  int distance = 0;
  int distance_2 = 0;
  int count = 0;
  for(int i = 0; i < n; ++i){
    for(int j = i + 1; j < n && i != j ; ++j){
      distance_2 = 0;
      for(int k = 0; k < d; ++k){
        distance_2 += (x[i*d + k] - x[j*d+k]) * (x[i*d+k] - x[j*d+k]);
        //printf("x[%d][%d] %d\n", i, k, x[i*d+k]);
        //printf("x[%d][%d] %d\n", j, k, x[j*d+k]);
        //printf("%d\n", distance_2);
      }
      distance = sqrt(float(distance_2));
      if(distance*distance == distance_2) count++;
      //printf("%d\n", distance);
      //printf("%d\n", distance_2);
    }
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;
 
int q;
bool b = false;

signed main() {
  cin >> q; //6
  int a[q-1]; //5
  for(int i = 0; i < q-1; i++){ //0, 4 = 5
    cin >> a[i];
  }
  
  int ans = a[0] + a[q-2]; 
  for(int i = 0; i < q-2; i++){ //
    ans += min(a[i], a[i+1]);
  }
  cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='+')
		{
			sum++;	
		}	
		if(s[i]=='-')
		{
			sum--;
		}
	}
	cout<<sum;
    return 0;
}




Measured memory_bytes: 256