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

using namespace std;

int main() {
    vector<int> A;
    int q;
    cin >> q;
    for (int i=0; i<q; i++) {
        int code;
        cin >> code;
        switch (code) {
            case 0: {
                int x;
                cin >> x;
                A.push_back(x);
            } break;
            case 1: {
                int p;
                cin >> p;
                cout << A[p] << endl;
            } break;
            case 2: {
                A.erase(A.begin()+A.size()-1);
            } break;
            default : break;
        }
    }
}


Measured memory_bytes: 3868
H, W = gets.split.map(&:to_i)
c = []
H.times do
  c << gets.chomp
end
d = [[0, -1], [0, 1], [-1, 0], [1, 0]]
ans = "Yes"
H.times do |h|
  W.times do |w|
    if c[h][w] == "#"
      cnt = 0
      d.each do |(dx, dy)|
        if (0 <= w + dx && w + dx < W) && (0 <= h + dy && h + dy < H)
          cnt += (c[h + dy][w + dx] == "#" ? 1 : 0)
        end
      end
      ans = "No" if cnt == 0
    end
  end
end

puts ans


Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
	int n;
	vector<int> a;
	cin >> n;
	int temp;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		a.push_back(temp);
	}

	ll sum = 0;
	int count_minus = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] < 0) {
			a[i] = -a[i];
			count_minus++;
		}
		sum += a[i];
	}


	for (int i = 0; i < n; i++) {
		if (a[i] == 0) {
			cout << sum << endl;
			return 0;
		}
	}

	if (count_minus % 2 == 0) {
		cout << sum << endl;
		return 0;
	}

	int min = 1000000000;
	for (int i = 0; i < n; i++)
		if (min >= a[i])
			min = a[i];
	cout << sum - min * 2 << endl;
	return 0;
}

Measured memory_bytes: 892
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a
AC
"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens = set(forbiddens)
    ans = N
    repeat = True
    
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
                
    return ans


def main(args):
    # N, K = 9999, 1
    # forbiddens = [9]
    N, K = map(int, input().split())
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
#define fat 998244353 
#define INF 1e9
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);
using namespace std;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}


int main()

{
    int n ;
    cin>>n;
    int d1[n] , d2[n];

    for(int i = 0 ; i < n ; i++)cin>>d1[i]>>d2[i];
    int cnt = 0;
    for(int i = 0 ; i < n ; i++)
    {
        if(d1[i]==d2[i])cnt++;
        else
        {
            cnt=0;
        }


        if(cnt==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10));
  vector<vector<int>> p(n, vector<int>(11));
  rep(i, 0, n) rep(j, 0, 10) cin >> f[i][j];
  rep(i, 0, n) rep(j, 0, 11) cin >> p[i][j];

  ll ans = -(1 << 30);
  rep(b, 1, 1 << 10) {
    ll cc = 0;
    rep(i, 0, n) {
      int c = 0;
      rep(j, 0, 10) if ((b >> j & 1) && f[i][j]) c++;
      cc += p[i][c];
    }
    ans = max(ans, cc);
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int dp[k+1];
  for(int i=0;i<=k;i++)
  	dp[i]=2;
  for(int i=1;i<=k;i++)
  {
    for(int j=0;j<n;j++)
    {
      if(i<a[j])
        continue;
      else if(dp[i-a[j]]==2)
      	dp[i]=1;
    }
  }
  if(dp[k]==1)
    cout<<"First";
  else
    cout<<"Second";

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a = "CF", b;
	cin >> b;
	int alen = a.length(), blen = b.length();
	int u = 0;
	for(int i = 0; i < blen; i++)
		if(u >= alen)	break;
	    else if(a[u] == b[i])	u++;
	if(u <= alen - 1)	printf("No\n");
	else	printf("Yes\n");
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<list<pair<int, int>>> V(N);
    for(int ii=0; ii<N-1; ii++){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        V[a].push_back({b, c});
        V[b].push_back({a, c});
    }
    vector<int> ans(N, -1);
    vector<int> tmp(N);
    tmp[0] = 0;
    ans[0] = 0;
    int jj=1;
    for(int ii=0; ii<N; ii++){
        int cur = tmp[ii];
        for(auto& c : V[cur]){
            if(ans[c.first] != -1) continue;
            if(c.second%2==0){
                ans[c.first] = ans[cur];
            }else{
                ans[c.first] = (ans[cur]==0) ? 1 : 0;
            }
            tmp[jj] = c.first;
            jj++;
        }
    }
    for(auto& z : ans){
        cout << z << endl;
    }
    return 0;
}


Measured memory_bytes: 9088
# coding: utf-8
# Your code here!

s = int(input())
tmp = s
ctr = 1
array = [s]

while True:
    ctr += 1
    if tmp % 2 == 0:
        tmp = tmp // 2
    else:
        tmp = 3 * tmp + 1
    if tmp in array:
        print(ctr)
        exit()
    else:
        array.append(tmp)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<cmath>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
const unsigned int M = 1000000007;
using namespace std;
int removed(int arr[],int num)
{
    int i,j,k;
for(i=0; i<num; i++)
    {
        for(j=i+1; j<num; j++)
        {
            if(arr[i] == arr[j])
            {
                for(k=j; k<num; k++)
                {
                    arr[k] = arr[k + 1];
                }
 
                num--;
                j--;
            }
       }
    }
    return num;
}
int main()
{
int n,c; cin>>n; int a[n];
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n); c=removed(a,n);
cout<<c;
return 0;
}

Measured memory_bytes: 3640
from fractions import gcd

N, X = map(int, input().split())
X_list = list(map(int, input().split()))

dX = [abs(X - x) for x in X_list]
if len(dX) == 1:
    print(dX[0])
    exit(0)

D = [abs(X_list[i] - X_list[i + 1]) for i in range(0, N - 1)]
res = D[0]
for x in D[1:]:
    res = gcd(res, x)

ans = 0
for d in dX:
    ans = max(gcd(res, d), ans)
print(ans)


Measured memory_bytes: 92052
N = int(input())
ans = float('inf')
for i in range(N+1):
    j = i
    count = 0
    t=N-i
    while j > 0:
        count += j%6
        j=j//6
    while t > 0:
        count += t%9
        t=t//9
    ans = min(ans,count)
print(ans)


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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int x;
    int count=0;
    for(int i=1;i<=n;i++){
        x=i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10;
      //  cout<<x<<endl;
        if(a<=x&&x<=b){
            count+=i;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
import numpy as np
from fractions import gcd

def lcm(x, y):
    return x * y // gcd(x, y)
A, B, C, D = [int(x) for x in input().split(" ")]
n_targets = B - A + 1

n_compC = n_targets - (B // C - (A - 1) // C)
n_compD = n_targets - (B // D - (A - 1) // D)
n_compCandD = n_targets - (B // lcm(C, D) - (A - 1) // lcm(C, D))

print(n_compC + n_compD - n_compCandD)

Measured memory_bytes: 13568
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

struct spi {
    string s;
    ll p;
    ll idx;
};

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl();
        vector<spi> ans;
        rep(i, n) {
            string s = ins();
            ll p = inl();
            spi tmp;
            tmp.s = s;
            tmp.p = p;
            tmp.idx = i;
            ans.eb(tmp);
        }
        sort(all(ans), [](spi &a, spi &b) {
            if (a.s == b.s) return a.p  > b.p;
            else return a.s < b.s;
        });
        rep(i, n) {
            cout << ans[i].idx + 1 << endl;
        }

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N;
    cin >> N;

    vector<bool> P(56000, true);
    P[0] = false;
    P[1] = false;
    for (int i = 2; i < 250; i++) {
        if(P[i] == false){
            continue;
        }
        else{
            for (int j = i; i * j < 56000; j++) {
                P[i * j] = false;
            }
        }
    }
    vector<int> ans;
    for (int i = 1; i < 56000; i+=5) {
        if(P[i] == true){
            ans.push_back(i);
        }
    }
    for (int i = 0; i < N; i++) {
        printf("%d ", ans[i]);
    }
    printf("\n");

}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,B,X; cin >> A >> B >> X;
    if(A<=X && X<=A+B) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
/*
int dfs(int foo, int timer)
{
    //foo is node number
    if (finds[foo].first != -1)
        return timer;
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i, data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second = ++result;
    return result;
}
*/
int main(){
    string a;
    cin>>a;
    rep(i,a.length()){
        if(a[i]==',')
        a[i]=' ';

    }
    cout<<a<<endl;
    return 0;
}


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

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;

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

lld N;
lld hp[100010];

int main() {
  cin >> N;
  rep(i, N) {
    scanf("%lld", &hp[i]);
    if(hp[i] == 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  rep(i, N - 1) {
    lld big = hp[i];
    lld little = hp[i + 1];
    lld tmp;
    if(big < little) {
      tmp = big;
      big = little;
      little = tmp;
    }
    
    while(big % little != 0) {
      big %= little;
      tmp = big;
      big = little;
      little = tmp;
    }
    hp[i + 1] = little;
    if(hp[i + 1] == 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << hp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
import scala.io.StdIn

object Main {
  def main(args: Array[String]) = {
    val Array(n, m) = StdIn.readLine().split(" ").map(_.toInt)
    val As = StdIn.readLine().split(" ").map(_.toLong).sorted
    val l = Array.tabulate(m) { _ =>
      val Array(b, c) = StdIn.readLine().split(" ").map(_.toLong)
      (b.toInt, c)
    }.sortBy(_._2)(Ordering.Long.reverse)

//    l.foreach(println(_))

    val result = new Array[Long](n)

    l.foldLeft(0) {
      case (pre, (num, v)) =>
        var index = pre
        var nIndex = 0
        while (index < n && nIndex < num) {
          result(index) = v
          nIndex += 1
          index += 1
        }
        index
    }
//    result.foreach(a => print(s"$a, "))
//    println()
    val r = (As ++ result).sorted(Ordering.Long.reverse).take(n)
//    r.foreach(a => print(s"$a, "))
//    println()

    println(r.sum)
  }
}

Measured memory_bytes: 117856
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int K;
  cin >>N>>K;
  int x=1;
  rep(i,N) {
    x=min(x*2,x+K);
  }
  cout<< x<< endl;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int i,n,m,ans,a[100001];
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	ans=a[n]+1;
	for(i=1;i+m-1<=n;i++)ans=min(ans,a[i+m-1]-a[i]);
	printf("%d",ans);
}

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

int main(void) {
  long long N;
  cin >> N;
  vector<long long> A(N), B(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  long long ans;
  if (N % 2 == 1) {
    ans = B[N / 2] - A[N / 2] + 1;
  } else {
    ans = (B[N / 2] + B[N / 2 - 1]) - (A[N / 2] + A[N / 2 - 1]) + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6428
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        String name = sc.nextLine();

        System.out.println(solve(name));

        sc.close();
    }

    static String solve(String name) {
        return Arrays.stream(name.split(" ")).map(part -> part.substring(0, 1)).collect(Collectors.joining());
    }
}

Measured memory_bytes: 26964
import java.util.*;
import java.io.*;
public class Main {
	
	static final int NONUM=-1;
	public static void main(String[] args)throws IOException{
		final Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		NODE[] n = new NODE[a];
	
		for(int i=0;i<n.length;i++){
			int id=sc.nextInt();
			n[id]=new NODE();
			n[id].id = id;
			n[id].l = sc.nextInt();
			n[id].r = sc.nextInt();
			n[id].p = -1;
			n[id].s = -1;
			n[id].d = 0;
			n[id].t = "leaf";
			if(n[id].l != -1){
				n[id].d++;
				n[id].t = "internal node";
			}
			if(n[id].r != -1){
				n[id].d++;
				n[id].t = "internal node";
			}
		}
	     for(int i=0; i<a; i++){
	    	 if(n[i].l != -1){
	                n[n[i].l].p = n[i].id;
	            }
	            if(n[i].r != -1){
	                n[n[i].r].p = n[i].id;
	            }
	            if(n[i].l != -1 && n[i].r != -1){
	                n[n[i].l].s = n[i].r;
	                n[n[i].r].s = n[i].l;
	            }
	     }
		
	        for(int i=0; i<a; i++){
	            if(n[i].p == -1){
	                n[i].t = "root";
	                if(n[i].l != -1){
	                    getdepth(n, n[i].l, 1);
	                }
	                if(n[i].r != -1){
	                    getdepth(n, n[i].r, 1);
	                }
	            }
	            if(n[i].d == 0){
	                if(n[i].p != -1){
	                    getheight(n, n[i].p, 1);
	                }
	            }
	        }
		
		for(int i=0;i<a;i++){
			System.out.println("node "+n[i].id+": parent = "+n[i].p+", sibling = "+n[i].s+", degree = "+n[i].d+", depth = "+n[i].dep+", height = "+n[i].h+ ", "+n[i].t);
		}
	}
	
	static void getdepth(NODE[] n,int i,int d){
	     n[i].dep = d;
	        d++;
	        if(n[i].l != -1){
	            getdepth(n, n[i].l, d);
	        }
	        if(n[i].r != -1){
	            getdepth(n, n[i].r, d);
	        }
	        
	}	
	
	static void getheight(NODE[] n,int i, int h){
        if(h < n[i].h) h = n[i].h;
        else           n[i].h = h;
        h++;
        if(n[i].p != -1){
            getheight(n, n[i].p, h);
        }
	}
}
	
class NODE{
	int id;
	int r;
	int l;
	int p;
	int d;
	int dep;
	int h;
	int s;
	String t; 
}

Measured memory_bytes: 18084
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long A, B, C, K;

int main() {
	cin >> A >> B >> C >> K;
	if (K <= A) cout << K << endl;
	else if (K <= A + B) cout << A << endl;
	else cout << A - (K - A - B) << endl;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  REP(i, n) { cin >> l[i]; }
  sort(l.begin(), l.end());

  ll ans = 0;
  REP(i, n) {
    FOR(j, i + 1, n) {
      auto top = lower_bound(l.begin(), l.end(), l[i] + l[j]);
      auto under = upper_bound(l.begin(), l.end(), abs(l[i] - l[j]));
      ll c = top - under;
      c--;

      if (under - l.begin() <= i && i < top - l.begin()) {
        c--;
      }

      ans += c;
    }
  }

  cout << ans / 3 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a + b + c >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end())

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using vstr = std::vector<std::string>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;


void Main() {
    int n;
    cin >> n;
    vint x(n), y(n), h(n);

    rep(i, n)cin >> x[i] >> y[i] >> h[i];

    int index = -1;
    rep(i, n) {
        if (h[i] > 0)index = i;
    }

    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            bool flag = true;
            int H = h[index] + abs(x[index] - i) + abs(y[index] - j);

            rep(k, x.size()) {
                if (h[k] == 0) {
                    if (H - abs(x[k] - i) - abs(y[k] - j) > 0) {
                        flag = false;
                        break;
                    }
                }
                if (h[k] > 0) {
                    if (H != h[k] + abs(x[k] - i) + abs(y[k] - j)) {
                        flag = false;
                        break;
                    }
                }
            }

            if (flag) {
                cout << i << " " << j << " " << H << endl;
                return;
            }
        }
    }

}

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



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<ll> x(n);
  for (int i = 0; i < n; ++i) cin >> x[i];
  int l = 0;
  int r = k - 1;
  ll  result = min(abs(x[l]), abs(x[r])) + abs(x[r] - x[l]);
  while (r < n) {
    result = min(result, min(abs(x[l]), abs(x[r])) + abs(x[r] - x[l]));
    l++;
    r++;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1024
package main

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

type edge struct {
	to     int
	weight int
}

// -1:まだわかんない 0:白 1:黒
var color []int

func dfs(g [][]edge, v, now int) {
	color[v] = now

	for _, e := range g[v] {
		if color[e.to] != -1 {
			continue
		}

		if e.weight%2 == 0 {
			dfs(g, e.to, now)
		} else {
			dfs(g, e.to, 1-now)
		}
	}
}

func main() {
	n := getInt()
	graph := make([][]edge, n)
	for i := range graph {
		graph[i] = make([]edge, 0)
	}
	for i := 0; i < n-1; i++ {
		a, b, w := getInt()-1, getInt()-1, getInt()
		graph[a] = append(graph[a], edge{b, w})
		graph[b] = append(graph[b], edge{a, w})
	}
	color = make([]int, n)
	for i := range color {
		color[i] = -1
	}

	dfs(graph, 0, 0)

	for i := range color {
		fmt.Println(color[i])
	}
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// tmp := 200001
	// sc.Buffer(make([]byte, tmp), tmp)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 25216
#include <stdio.h>
int main(){
    int n,a,b,c,d,i,j,k;
    int room[4][3][10]={0};//棟階部屋
    scanf("%d",&n);//人数
    
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&a,&b,&c,&d);
        room[a-1][b-1][c-1]+=d;
        }
    
    for(k=0;k<4;k++){
        for(j=0;j<3;j++){
            for(i=0;i<10;i++){
                printf(" %d",room[k][j][i]);
            }
            printf("\n");
        }
        if(k!=3)
        printf("####################\n");
    }
}



Measured memory_bytes: 2140
'use strict';
function main(input) {
  input = input.split(" ");
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  const c = parseInt(input[2], 10);
  
  console.log(`${c} ${a} ${b}`);
}

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

Measured memory_bytes: 21064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BJudgeStatusSummary {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, ac = 0, wa = 0, tle = 0, re = 0;
        in>>N;
        REP(i, N){
            string S;
            in>>S;
            if(S=="AC") ++ac;
            else if(S=="WA") ++wa;
            else if(S=="TLE") ++tle;
            else ++re;
        }
        out<<"AC x "<<ac<<'\n';
        out<<"WA x "<<wa<<'\n';
        out<<"TLE x "<<tle<<'\n';
        out<<"RE x "<<re<<'\n';
    }
};


int main() {
	BJudgeStatusSummary solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

class union_find{
	int n;
	vector<int> a;
public:
	union_find(int N):a(N,-1),n(N){}
	int find(int x){
		if(a[x]<0) return x;
		return a[x]=find(a[x]);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x!=y){ a[x]+=a[y]; a[y]=x; n--; }
	}
	int size(){ return n; }
};

struct edge{
	int u,v,cost;
	bool operator<(const edge &e)const{ return cost<e.cost; }
};

bool is_connected(int n,const bool *sunk,int m,edge *E){
	union_find U(n);
	rep(i,m){
		int u=E[i].u,v=E[i].v;
		if(!sunk[u] && !sunk[v] && U.find(u)!=U.find(v)) U.unite(u,v);
	}
	return U.size()==1+count(sunk,sunk+n,true);
}

int find_MST(const bool *sunk,int m,const edge *E,union_find &U){
	int res=0;
	rep(i,m){
		int u=E[i].u,v=E[i].v;
		if(!sunk[u] && !sunk[v] && U.find(u)!=U.find(v)){
			U.unite(u,v);
			res+=E[i].cost;
		}
	}
	return res;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		int life[200];
		rep(u,n) scanf("%d",life+u);
		static edge E[200*199/2];
		rep(i,m){
			int u,v,c; scanf("%d%d%d",&u,&v,&c); u--; v--;
			E[i]=(edge){u,v,c};
		}
		sort(E,E+m);

		int order[200];
		{
			pair<int,int> tmp[200];
			rep(u,n) tmp[u]=make_pair(life[u],u);
			sort(tmp,tmp+n);
			rep(i,n) order[i]=tmp[i].second;
		}

		bool sunk[200]={}; // sizunda islands
		if(!is_connected(n,sunk,m,E)){ puts("0"); continue; }

		int i_end=n;
		rep(i,n){
			sunk[order[i]]=true;
			while(i<n-1 && life[order[i]]==life[order[i+1]]) sunk[order[++i]]=true;

			if(!is_connected(n,sunk,m,E)){ i_end=i; break; }
		}
		while(i_end>0 && life[order[i_end]]==life[order[i_end-1]]) i_end--;

		rep(u,n) sunk[u]=false;
		rep(i,i_end) sunk[order[i]]=true;

		union_find U(n);
		int ans=find_MST(sunk,m,E,U);
		for(int i=i_end-1;i>=0;i--){
			sunk[order[i]]=false;
			while(i>0 && life[order[i]]==life[order[i-1]]) sunk[order[--i]]=false;

			ans+=find_MST(sunk,m,E,U);
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef pair<int,int> pii;
int H,W;
vector<int> b;
vector<int> ans;
bool change=false;
bool used[1005][1005];
string board[1005];
int ope=0;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int blacknum=0;
queue<pair<int,int> > qp;
bool outrange(int y, int x)
{
  if(y<0 || y>=H || x<0 || x>=W || used[y][x] || board[y][x]=='#') return true;
  else return false;
}

bool outrangeused(int y, int x)
{
  if(y<0 || y>=H || x<0 || x>=W) return true;
  else return false;
}
int main(int argc,char const* argv[])
{
  memset(used,false,sizeof(used));
  cin >> H >> W;
  queue<pair<int,int> > qp;
  for (int i = 0; i < H; ++i)
    {
      cin >> board[i];
      for (int j = 0; j < W; ++j)
	{
	  if(board[i][j]=='#')
	    {
	      qp.push(pii(i,j));
	      blacknum++;
	    }
	}
    }
  queue<pair<int,int > > qp2;
  while(!qp.empty())
    {
      pii tmp=qp.front();
      qp.pop();
      int nowy=tmp.first;
      int nowx=tmp.second;
      used[nowy][nowx]=true;
      for (int k = 0; k < 4; ++k)
	{
	  int ny=nowy+dy[k];
	  int nx=nowx+dx[k];
	  if(!outrange(ny,nx))
	    {
	      qp2.push(pii(ny,nx));
	      board[ny][nx]='#';
	      used[ny][nx]=true;
	    }
	}	  
      //cout << qp.size() << ' ' << qp2.size() <<  endl;
      if(qp.size()==0)
	{
	  qp=qp2;
	  if(qp2.size()==0) break;
	  qp2=queue<pair<int,int> > ();
	  ope++;
	}
    }
  cout << ope << endl;
  return 0;
}


Measured memory_bytes: 10624
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


void solve() {
    int n;
    cin >> n;
    int u,v;
    LL ans = 0;
    REP(i,0,n) {
        ans += 1LL * (i+1) * (n-i);
    }
    REP(i,0,n-1) {
        cin >> u >> v;
        --u; --v;
        if (u > v) swap(u,v);
        ans -= 1LL * (u+1) * (n-v);
    }
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define mo 1000000007
using namespace std;
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll int n;
     cin>>n;
     ll int arr[n],sum{0};
     map<ll int,ll int>mp;
     for(int i=0;i<n;i++){
         cin>>arr[i];
         sum+=arr[i];
         mp[arr[i]]++;
     }
     ll int q;
     cin>>q;
     ll int a[q][2];
     for(int i=0;i<q;i++)
     {
         for(int j=0;j<2;j++)
             cin>>a[i][j];
     }
     for(int i=0;i<q;i++){
         ll int x=mp[a[i][0]];
         sum-=x*a[i][0];
         sum+=x*a[i][1];
      //   if(mp.find(a[i][1])!=mp.end())
            mp[a[i][1]]+=x;
//         else
//             mp[a[i][1]]=x;
         mp[a[i][0]]=0;
         cout<<sum<<endl;
     }
 return 0;    
}

Measured memory_bytes: 11744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
const long long int mod = 1000000007;

int main(){
	int a, b,c;
	bool ans = false;
	cin >> a >> b >> c;
	for (int i = 1; i <= a*b; i ++){
		if ((a*i) % b == c){
			ans = true;
		}
	}
	if (ans == true){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <numeric>

using namespace std;

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

    vector<int> d(n);
    for (int i = 0; i < n; i++)
        cin >> d[i];

    sort(d.begin(), d.end());


    cout << d[n / 2] - d[n / 2 - 1] << endl;
    return 0;
}

Measured memory_bytes: 768
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])
const [_, ...a] = stdin.split('\n').map(Number)

const ans = () => {
  const sorted = [...a].sort((a, b) => b - a)
  const max = sorted[0]
  const next = sorted[1]

  const resArr = []

  for (let i = 0; i < n; i++) {
    if (a[i] !== max) {
      resArr.push(max)
    } else {
      resArr.push(next)
    }
  }

  for (let i = 0; i < n; i++) {
    console.log(resArr[i])
  }
}

ans()


Measured memory_bytes: 72184
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof a)
#define rep(i, a, b) for(int i(a), i##_END_(b); i <= i##_END_; i++) 
#define drep(i, a, b) for(int i(a), i##_END_(b); i >= i##_END_; i--)
using namespace std;
template<class T> inline bool tomax(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T> inline bool tomin(T &a, T b) {return b < a ? a = b, 1 : 0;}
typedef long long ll;
typedef double db;

template<int N, int M, class T> struct Link { 
#define erep(k, G, o) for(int k(G.HEAD[o]); k; k = G.NXT[k])
    int HEAD[N], NXT[M], tot; T W[M];
    void add(int x, T w) {NXT[++tot] = HEAD[x]; W[HEAD[x] = tot] = w;}
    T& operator[] (int x) {return W[x];}
};

const int N = 1e5 + 5, MOD = 1e9 + 7;
Link<N, N * 2, int> G;

int fac[N], ifac[N];
int qkpow(int x, int k) {
    int ans = 1;
    for(; k; k >>= 1, x = (ll) x * x % MOD) 
        if(k & 1) ans = (ll) ans * x % MOD;
    return ans;
}
void init() {
    int n = 1e5;
    fac[0] = 1;
    rep(i, 1, n) fac[i] = (ll) fac[i - 1] * i % MOD;
    ifac[n] = qkpow(fac[n], MOD - 2);
    drep(i, n - 1, 0) ifac[i] = (ll) ifac[i + 1] * (i + 1) % MOD;
}
int chs(int x, int y) {
    if(y > x) return 0;
    return (ll) fac[x] * ifac[y] % MOD * ifac[x - y] % MOD;
}

int k;
int dfs(int o, int f, int c) {
    int son = 0;
    erep(k, G, o)
        son += (G[k] != f);
    int ans = (ll) chs(k - c, son) * fac[son] % MOD;
    erep(k, G, o) {
        int v = G[k];
        if(v == f) continue;
        ans = (ll) ans * dfs(v, o, min(c + 1, 2)) % MOD;
    }
    return ans;
}

int main() {
    // freopen("data.in", "r", stdin);
    init();
    int n, a, b;
    scanf("%d%d", &n, &k);
    rep(i, 2, n) {
        scanf("%d%d", &a, &b);
        G.add(a, b); G.add(b, a);
    }
    printf("%lld\n", (ll) k * dfs(1, 0, 1) % MOD);
    return 0;
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
signed main(void){
	ios::sync_with_stdio(false);
	int d,ans;
	while(cin>>d){
		ans=0;
		for(int i=0;i<600;i+=d)
			ans+=i*i*d;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}

void dfs(vector<char> s,int depth, int max_depth,int type)
{
	if(depth == max_depth)
	{
		for(int i=0; i<max_depth; i++)
		{
			cout<<s[i];
		}
		cout<<endl;
		return;
	}

	for(int i=0; i<type; i++)
	{
		vector<char> new_s = s;
		s[depth] = 'a' + i;
		dfs(s,depth+1,max_depth,type);
	}
	vector<char> new_s = s;
	s[depth] = 'a' + type;
	dfs(s,depth+1,max_depth,type+1);


}

int main()
{
	//全探索
	int N;
	cin>>N;

	vector<char> s(N);
	dfs(s,0,N,0);
}

Measured memory_bytes: 1536
while true
    n = gets.to_i
    break if n == 0
    score = []
    n.times{|i|
        line = gets.chomp
        score << [line[0], line.count("0"), line.count("1"), i]
    }
    score.sort_by{|a, b, c, d| [-b, c, d]}.each{|a, b, c, d| puts a}
end


Measured memory_bytes: 6880
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
typedef long long LL;
const int N = 100100;
inline int getint()
{
	int r = 0,s = 0;char c = getchar();for(;!isdigit(c);c = getchar()) s |= c == '-';
	for(;isdigit(c);c = getchar()) r = (((r << 2) + r) << 1) + (c ^ '0');return s ? -r : r;
}
int n,s,x[N];
LL p[N],ans = 0;
int main()
{
	n = getint(),s = getint();
	for(int i = 1;i <= n;i++) x[i] = getint(),p[i] = getint();
	for(int l = 1,r = n,d = -1;;)
	{
		if(x[l] >= s){printf("%lld\n",ans + x[r] - s);break;}
		if(x[r] <= s){printf("%lld\n",ans + s - x[l]);break;}
		if(p[l] >= p[r])
		{
			if(d != 0) ans += x[r] - x[l];
			p[l] += p[r--];
			d = 0;
		}
		else
		{
			if(d != 1) ans += x[r] - x[l];
			p[r] += p[l++];
			d = 1;
		}
	}
	return 0;
}


Measured memory_bytes: 1280
S=input()

count=0
if len(S)%2==0:
    for i in range(len(S)//2):
        if S[i]!=S[-i-1]:
            count+=1
else:
    for i in range((len(S)-1)//2):
        if S[i]!=S[-i-1]:
            count+=1

print(count)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            if(4*i+7*j==n){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  sort(t.begin(), t.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int j = i;
    while (j < n && j - i + 1 <= c && t[j] - t[i] <= k) {
      j++;
    }
    ans++;
    i = j - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    int X,N,i, x;
    bool p[100] = {};
    cin >> X >> N;
    for (i=0;i<N;i++){
        cin >> x;
        p[x-1] = true;
    }
    X = X-1;

    for(i=0;i<100;i++){
        x = X-i;
        if(x >= 0){
            if(p[x]==false){
                cout << (x+1);
                return 0;
            }
        }
        else{
            cout << 0;
            return 0;
        }
        x = X + i;
        if(x < 100){
            if(p[x]==false){
                cout << (x+1);
                return 0;
            }
        }
        else{
            cout << 101;
            return 0;
        }

    }
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m; cin >> n >> m;
  vector<int> a(n);
  bitset<10> confirmed(0);
  
  for (int i = 0; i < m; i++) {
    int s, c; cin >> s >> c; s--;
    if (confirmed[s] && a[s] != c) {
      cout << -1 << '\n';
      return 0;
    } else if (s == 0 && c == 0 && n > 1){
      cout << -1 << '\n';
      return 0;
    } else {
      a[s] = c;
      confirmed.set(s);
    }
  }
  if (!confirmed[0] && n > 1) a[0] = 1;
  string res = "";
  for (auto &d : a) {
    res += to_string(d);
  }
  cout << res << '\n';
  return 0;
}

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

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

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

	int ans = 2000000000;
	for(int i = 0;i <= n-k;i++){
		int l = x[i], r = x[i+k-1];
		int a = min(abs(l)+abs(l-r), abs(r)+abs(l-r));
		if(ans > a) ans = a;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#include <limits>

// 各点への最短経路 dijkstra
template<typename dist_t>
class Dijkstra {
    using elem_t = pair<dist_t, int>;

    int n; // 頂点数
    vector<elem_t> *G;

public:

    static const dist_t INF;

    Dijkstra(int _n) : n(_n), G(new vector<elem_t>[(size_t)n]) {}

    Dijkstra(int _n, vector<elem_t>* &_G) : n(_n), G(_G) {}

    inline void add_edge(int from, int to, dist_t dist=1) {
        G[from].push_back(elem_t{dist, to});
    }

    struct result {
        result(int _n, int k) : n(_n), d(new dist_t[(size_t)_n]) {
            fill(d, d+n, INF); 
            d[k] = 0;
        }
        auto &operator[](int i) { return d[i]; } 
        auto begin() { return d; }
        auto end()   { return d + n; }
        operator dist_t*() { return d; } // dist_t* へのキャスト

        bool unreachable(int i) { return d[i] == INF; }  // 視点から到達不可能かどうか
    private:
        const int n;
        dist_t *d;
    };

    inline result operator()(int start) {
        result d(n, start);

        priority_queue< elem_t, vector<elem_t>, greater<elem_t> > que;
        que.push(elem_t{0, start});

        while (!que.empty()) {
            elem_t p = que.top(); que.pop();
            int now = p.second;
            if (d[now] < p.first) continue;

            for (auto &g:G[now]) {
                int to = g.second;
                dist_t newd = g.first + d[now];

                if (d[to] > newd) {
                    d[to] = newd;
                    que.push(elem_t(d[to], to));
                }
            }
        }
        return d;
    }

    auto &operator[](int i) { return G[i]; } 
    auto begin() { return G; }
    auto end()   { return G + n; }
};

template<typename dist_t>
const dist_t Dijkstra<dist_t>::INF = numeric_limits<dist_t>::max();

/* Constructers
 *
 * Dijkstra(int _n) 
 * Dijkstra(int _n, vector<elem_t>* &_G)
 */


#define INF (ll)(1e17)
#define MAX_S 5010

#define node(actual, bit, s) ((2 * actual + bit) * MAX_S + s)

int main() {
    int n, m;
    ll s;
    cin >> n >> m >> s;
    ll U[m], V[m], A[m], B[m];
    Dijkstra<ll> dij(2 * n * MAX_S);
    for (int i=0; i<m; i++) {
        cin >> U[i] >> V[i] >> A[i] >> B[i];
        U[i]--; V[i]--;
        for (int j=A[i]; j<MAX_S; j++) {
            dij.add_edge(node(U[i], 1, j), node(V[i], 0, j-A[i]), B[i]);
            dij.add_edge(node(V[i], 1, j), node(U[i], 0, j-A[i]), B[i]);
        }
    }
    ll C[n];
    ll D[n];
    for (int i=0; i<n; i++) {
        cin >> C[i] >> D[i];
        for (int ss=0; ss<MAX_S; ss++) {
            if (ss + C[i] < MAX_S)
                dij.add_edge(node(i, 1, ss), node(i, 1, ss+C[i]), D[i]);
            dij.add_edge(node(i, 0, ss), node(i, 1, ss), 0);
        }
    }
    auto res = dij(node(0, 0, min(MAX_S-1, (int)s)));
    for (int i=1; i<n; i++) {
        ll ans = INF;
        for (int j=0; j<MAX_S; j++) {
            ans = min({ans, res[node(i, 0, j)], res[node(i, 1, j)]});
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 60596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	vector<int> HeightOfMountain(10);
	for(int i = 0; i < 10; i++){
		cin >> HeightOfMountain[i];
	}
	sort(HeightOfMountain.begin(), HeightOfMountain.end(), greater<int>());
	cout << HeightOfMountain[0] << endl;
	cout << HeightOfMountain[1] << endl;
	cout << HeightOfMountain[2] << endl;
	return 0;
}

Measured memory_bytes: 3164
n,q = map(int,input().split())
ki = [[] for i in range(n+1)] 
c = [0] * (n+1)

for i in range(n-1):
    a,b = map(int,input().split())
    ki[a].append(b)

for i in range(q):
    p,x = map(int,input().split())
    c[p] += x

st = [1]
while st:
    tmp = st.pop()
    for i in ki[tmp]:
        c[i] += c[tmp]
    st += ki[tmp]

print(*c[1:])

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

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

int main(){

    int A, B;
    string S, T,U;
    cin >> S >> T >> A >> B >> U;

    if(U==S)
        cout << A - 1 <<" "<< B << endl;
    else
        cout << A <<" "<< B - 1 << endl;

}




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

bool edge[8][8];
bool visited[8];

int dfs(int N,int now,bool visited[]){
  int ans=0;
  bool allv=true;
  for (int i=0;i<N;i++){
    if (visited[i]==false){
      if (edge[now][i] or edge[i][now]){
        visited[i]=true;
        ans+=dfs(N,i,visited);
        visited[i]=false;
      }
      allv=false;
    }
  }
  if (allv){
    return 1;
  }
  return ans;
}
int main(){
  int N,M;
  cin >> N >> M;
  int a,b;
  for (int i=0;i<M;i++){
    cin >> a >> b;
    edge[a-1][b-1]=true;
  }
  visited[0]=true;
  cout << dfs(N,0,visited) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;

bool is_prime[1001000];

int main(){
	fill(is_prime, is_prime + 1001000, 1);
	is_prime[0] = 0;
	is_prime[1] = 0;
	for (int i = 2; i <= 1000000; i++){
		if (is_prime[i]){
			for (int j = i * 2; j <= 1000000; j += i){
				is_prime[j] = 0;
			}
		}
	}

	while (cin >> n&&n){
		int ans = 0;
		FOR(i, 1, n / 2 + 1){
			if (is_prime[i] && is_prime[n - i]){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2136
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll z(ll a){
  if(a<0)return -a;
  return a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll nCr(int n,int k){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(void){
  int n;
  scanf("%d",&n);
  char s[10001];
  scanf("%s",s);
  char a[53]={"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"};
  FOR(strlen(s))PRC(a[s[i]-'A'+n]);
  PRS("");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long n,i,a[100005],f[100005];
int main()
{
    cin >> n ;
    for (i=1; i<=n; i++) cin >> a[i];
    f[1] = 0;
    f[2] = abs(a[2] - a[1]);
    for (long i=3; i<=n; i++) {
        f[i] = min(f[i-1] + abs(a[i]- a[i-1]),f[i-2] + abs(a[i]- a[i-2]));
    }
    cout << f[n];
    return 0;
}


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

using namespace std;

int main(){
	string s;
	getline(cin, s);
	cout << ((s.size() > 3 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256