akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, s[110000], co = 0;
set<ll> se;

int main() {
	bool ok = true;
	cin >> n;
	REP(i, n) {
		cin >> s[i];
		se.insert(s[i]);
	}
	if (se.size() > 2) ok = false;
	else {
		sort(s, s + n);
		ll a = s[0], b = s[n - 1];
		if (b - a > 1) ok = false;
		else {
			REP(i, n) {
				if (s[i] == a) co++;
			}
			if (co != a) ok = false;
			if (se.size() == 1 and a <= 2) ok = true;
			else if (se.size() == 1 and (a == n - 1 or a == a / 2 + 1)) ok = true;
			else if (se.size() == 1 and n % a == 0) ok = true;
			else if (co == 1 and a < n - 2) ok = true;
			else if (a == n / 2 and co == 2 and n % 2 == 0) ok = true;
		}
	}
	//cout << co << endl;
	cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 5760
n, m = map(int, input().split())

count = [0 for i in range(m)]

for j in range(n):
    check = list(map(int, input().split()))
    for k in range(check[0]):
        count[check[k+1] - 1] += 1

ans = 0
for l in range(len(count)):
    if count[l] == n:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;

ll N;
ll P[8], Q[8];
int main() {
    cin >> N;

    string p_s = "", q_s = "";
    rep(i, N) {
        string t;
        cin >> t;
        p_s += t;
    } 
    rep(i, N) {
        string t2;
        cin >> t2;
        q_s += t2;
    } 

    vector<ll> v; 
    rep(i, N) v.push_back(i + 1);

    ll p = 0, q = 0;
    ll num = 0;
    do {
        num++;
        string tmp;
        for (ll i = 0; i < v.size(); i++) {
            // printf("%d ", v[i]);
            tmp += to_string(v[i]);
        }
        if (tmp == p_s) p = num;
        if (tmp == q_s) q = num;
        // printf("\n");
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(p - q) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    string s; cin >> s;
    int zero = 0, one = 0;

    for(auto a:s){
        if(a == '1') one++;
        if(a == '0') zero++;
    }

    put(s.size() - abs(one - zero));
}

Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"


using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<vector<int>>edge(N + 1);
	vector<int>dir(N + 1);
	for (int i = 0; i < N - 1 + M; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
		dir[R]++;
	}
	queue<int>Q;
	for (int i = 1; i <= N; i++) {
		if (!dir[i])Q.push(i);
	}
	vector<int>parent(N + 1);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			dir[i]--;
			parent[i] = cn;
			if (!dir[i])Q.push(i);
		}
	}
	for (int i = 1; i <= N; i++)cout << parent[i] << endl;
}

Measured memory_bytes: 7040
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
int ans;
int n;
int s;
void count_ans(int k,int C,int j){
if(k==n){
if(C==s){
ans++;
}
}else{
for(int i=j+1;i<10;i++){
count_ans(k+1,C+i,i);
}
}
}
int main(){
while(cin>>n>>s,(n!=0)||(s!=0)){
ans=0;
count_ans(0,0,-1);
cout<<ans<<endl;
}
}

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

Measured memory_bytes: 3712
import sys
sys.setrecursionlimit(10**7) #再帰関数の呼び出し制限
N, M = map(int, input().split())
A = [[0]* N for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    A[a-1][b-1] = 1
    A[b-1][a-1] = 1
visited=[1]+[0]*(N-1)
def DFS(now, visited):
    ans = 0
    if not 0 in visited:
        return 1
    for i in range(N):
        if A[now][i] == 0:
            continue
        if visited[i] == 1:
            continue
        visited[i] = 1
        ans += DFS(i, visited)
        visited[i] = 0
    return ans
print(DFS(0, visited))

Measured memory_bytes: 43100
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int n) {
    int[] dptable = new int[n + 1];
    for (int i = 1; i <= n; i++) {
      dptable[i] = dptable[i - 1] + 1;
    }
    
    for (int v1 : new int[]{6, 9}) {
      for (int v = v1; v <= n; v *= v1) {
        for (int i = v; i <= n; i++) {
          dptable[i] = Math.min(dptable[i], dptable[i - v] + 1);
        }
      }
    }
    return dptable[n];
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22996
a,b,c,k = map(int,input().split())
cnt = 0
if a < k:
    cnt += a
    k -= a
else:
    cnt += k
    print(cnt)
    exit()
if b < k:
    cnt += 0
    k -= b
else:
    print(cnt)
    exit()
if c < k:
    cnt -= c
    k -= c
else:
    cnt -= k
    print(cnt)
    exit()

Measured memory_bytes: 9200
n,k = map(int,input().split())
d = input().split()

while True:
    s = str(n)
    f = 1
    for i in range(len(s)):
        if s[i] in d:
            f = 0
        else:
            pass

    if f:
        print(s)
        break
    else:
        n += 1

Measured memory_bytes: 3060
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N - 1)]

Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for i, (ai, bi, ci) in enumerate(abc):
    graph[ai - 1].append((bi - 1, ci))
    graph[bi - 1].append((ai - 1, ci))

import heapq
MY_INF = None
    
q = [(0, K - 1)]
d = [MY_INF] * N
d[K - 1] = 0
while len(q) > 0:
    dist, src = heapq.heappop(q)
    for dst, c_dst in graph[src]:
        dist_tmp = dist + c_dst
        if d[dst] == None or d[dst] > dist_tmp:
            d[dst] = dist_tmp
            heapq.heappush(q, (dist_tmp, dst))

for i, (xi, yi) in enumerate(xy):
    print(d[xi - 1] + d[yi - 1])

Measured memory_bytes: 87576
import java.util.*;

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

    long a = sc.nextInt();
    long b = sc.nextLong();

    if((a + b) % 2 == 0){
      System.out.println((a + b) / 2);
    } else {
      System.out.println("IMPOSSIBLE");
    }

  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b;
  cin>>a>>b;
  if(abs(a-b)%2==1)
    cout<<"IMPOSSIBLE"<<endl;
  else
    cout<<abs(a-b)/2+min(a,b)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	vector<pair<int, int>> point_of_black;
	vector<vector<char>> field;
	int number_of_white_tile = 0;
	long long count_actions = 0;
	int H, W;
	cin >> H >> W;
	field.resize(H + 2);
	for (int i = 0; i <= H + 1; ++i) {
		field[i].resize(W + 2);
		for (int j = 0; j <= W + 1; ++j) {
			field[i][j] = '0';
		}
	}
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			cin >> field[i][j];
			if (field[i][j] == '#')point_of_black.push_back(make_pair(i, j));
			else ++number_of_white_tile;
		}
	}

	vector<pair<int, int>> point_of_white;
	while (number_of_white_tile != 0) {
		while (point_of_black.size() != 0) {
			int h = point_of_black.back().first;
			int w = point_of_black.back().second;
			if (field[h - 1][w] == '.') point_of_white.push_back(make_pair(h - 1, w));
			if (field[h][w - 1] == '.') point_of_white.push_back(make_pair(h, w - 1));
			if (field[h + 1][w] == '.') point_of_white.push_back(make_pair(h + 1, w));
			if (field[h][w + 1] == '.')	point_of_white.push_back(make_pair(h, w + 1));
			point_of_black.pop_back();
		}
		
		while (point_of_white.size() != 0) {
			int h = point_of_white.back().first;
			int w = point_of_white.back().second;
			if(field[h][w] == '.'){
				field[h][w] = '#';
				point_of_black.push_back(make_pair(h, w));
				--number_of_white_tile;
			}
			point_of_white.pop_back();
		}
		++count_actions;

	}

	cout << count_actions << endl;
	return 0;
}

Measured memory_bytes: 20584
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    string S;
    ll w;
    cin >> S >> w;

    for (ll i = 0; i < S.size(); i += w) {
        cout << S[i];
    }

    cout << endl;

}

Measured memory_bytes: 256
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    N, X, Y = LI()
    X -= 1
    Y -= 1
    cnt = [0] * N

    for i in range(N):
        for j in range(i + 1, N):
            dist = min(abs(i - j), abs(X - i) + 1 +
                       abs(Y - j), abs(Y - i) + 1 + abs(X - j))
            cnt[dist] += 1

    for i in cnt[1:]:
        print(i)


main()


Measured memory_bytes: 9604
#include<stdio.h>
int main(void)
{
	int n,p[2],g[2],d[2],a=0,i,z;
	scanf("%d%d%d %d%d",&p[0],&p[1],&n,&p[0],&p[1]);
	for(i=1;i!=n;i++){
		scanf("%d%d",&g[0],&g[1]);
		z=0;
		while(1){
			d[0]=g[0]-p[0];
			d[1]=g[1]-p[1];
			if(d[0]!=0&&d[1]!=0&&z==0){
				if(d[0]>0&&d[1]>0){
					p[0]++;
					p[1]++;
					a++;
				}
				else if(d[0]<0&&d[1]<0){
					p[0]--;
					p[1]--;
					a++;
				}
				else{
					z=1;
				}
			}
			else if(d[0]!=0){
				if(d[0]>0)
					p[0]++;
				else
					p[0]--;
				a++;
			}
			else if(d[1]!=0){
				if(d[1]>0)
					p[1]++;
				else
					p[1]--;
				a++;
			}
			if(d[0]==0&&d[1]==0)
				break;
		}
	}
	printf("%d\n",a);
}

Measured memory_bytes: 2712
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(ll i=a;i<n;i++)
#define rfore(i, a, b) for(ll i = b - 1; i >= (ll)a; i--)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define mm(a,b) memset(a,b,sizeof(a));
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define INFI ((ll)1e15)
#define MINI ((ll)-1e15)
#define EPS 1e-9
#define endl "\n"
using namespace std;
typedef long long ll;  
typedef long double ld;
const ll MOD = 1e9+7;     
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const ll MAXN =300005;
ll n,t,q,x,s,k,m;
int main(){
    cin >> n;
    ll sum = 0, j = 1, k = log2(n)+1;
    while(k--)sum+=j, j*=2;
    cout << sum;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int i;
	int *a;
	a = (int*)malloc(n*sizeof(int));

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

	}


	int total = 0;
	for (i = 0; i < n; i++) {
		total += a[i];
	}
	int ave;
	ave = total/n;
	int m[3];
	m[0] = ave - 1;
	m[1] = ave;
	m[2] = ave + 1;
	int ans[3];
	ans[0] = 0;
	ans[1] = 0;
	ans[2] = 0;
	for (i = 0; i < n; i++) {
		ans[0] += (int)pow((a[i] - m[0]), 2);
	}
	for (i = 0; i < n; i++) {
		ans[1] += (int)pow((a[i] - m[1]), 2);
	}
	for (i = 0; i < n; i++) {
		ans[2] += (int)pow((a[i] - m[2]), 2);
	}
	int answer= 100000000;
	for (i = 0; i < 3; i++) {
		if (answer > ans[i]) {
			answer = ans[i];
		}
		//cout << ans[i]<< " ";
	}
	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = K;

        for(int i=0; i<N-1; i++){
            ans *= K - 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21588
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>

using namespace std;


int main(){

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

  for(int i = 0; i < n; i++){
    int id, k, x;
    cin >> id >> k;
    for(int j = 0; j < k; j++){
      cin >> x;
      m[i][x - 1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n - 1; j++){
      cout << m[i][j] << " ";
    }
    cout << m[i][n - 1] << endl;
  }

  return 0;
}



Measured memory_bytes: 3120
#include<stdio.h>
int main(void)
{
  int H,W,h,w;
  
  scanf("%d",&H);
  scanf("%d",&W);
  scanf("%d",&h);
  scanf("%d",&w);
  
  printf("%d",H*W-h*W-w*H+h*w);
  
  return 0;
}

Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    N, M = map(int, input().split()) # 頂点の数、辺の数
    edge = [[] for i in range(2)] # rangeに頂点の数。繋がっている頂点を投入するリスト
    for i in range(M): # rangeに辺の数
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        if a==0 :
            edge[0].append(b)
        elif b==N-1:
            edge[1].append(a)
    if len(set(edge[0])&set(edge[1]))>=1:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

resolve()

Measured memory_bytes: 65884
//API???????????????
import java.util.Scanner;
import java.io.IOException;
class Main {
  	public static void main(String[] args) throws IOException{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		Nodes nodes = new Nodes();
		Node[] node = new Node[n];
		nodes.nodes = node;
		for(int i = 0;i < n;i++){
			node[i] = new Node(i);
		}
		
		for(int i = 0;i < n; i++){
			int id = scan.nextInt();
			int left = scan.nextInt();
			int right = scan.nextInt();
			if(left != -1) node[left].parent = id;
			if(right != -1) node[right].parent = id;
			node[id].left = left;
			node[id].right = right;
			if(left != -1 && right != -1){
				node[left].sibling = right;
				node[right].sibling = left;
			}
		}
		
		int root = 0;
		
		while(node[root].parent != -1){
			root = node[root].parent;
		}
		
		nodes.setDepth(root, 0);
		node[root].height = nodes.setHeight(root);
		
		for(int i = 0; i < n; i++){
			StringBuilder sb = new StringBuilder();
			int d = 0;
			if(node[i].left != -1) d++;
			if(node[i].right != -1) d++;
			
			sb.append("node " + i + ": parent = " + node[i].parent + ", sibling = " + node[i].sibling + ", degree = " + d + ", depth = " + node[i].depth + ", height = " + node[i].height + ", ");
			//????????????????????°
			if(node[i].parent == -1) sb.append("root\r\n");
			//???????????????????????????????????°
			else if(d == 0) sb.append("leaf\r\n");
			//????????\???
			else sb.append("internal node\r\n");
			System.out.print(sb);
		}
	}
}

class Node{
	int id;
	int parent = -1;
	int left = -1;
	int right = -1;
	int sibling = -1;
	int depth = -1;
	int height = -1;

	public Node(int id) {
		this.id = id;
	}
}

class Nodes{
	/*
	List<Node> nodes;
	/*/
	Node[] nodes;
	/**/
	
	//-1??????????????§??±????????£?????????
	public void setDepth(int id, int d){
		int l = nodes[id].left;
		int r = nodes[id].right;
		if(l != -1) setDepth(l, d + 1);
		if(r != -1) setDepth(r, d + 1);
		nodes[id].depth = d;
	}
	
	public int setHeight(int id){
		if(id == -1) return -1;
		
		int l = nodes[id].left;
		int r = nodes[id].right;
		nodes[id].height = Math.max(setHeight(l), setHeight(r)) + 1; 
		return nodes[id].height;
	}
}



Measured memory_bytes: 26356
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0&&c>0)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes\n";
			return 0;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No\n";
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 3640
s = input()
y, m, d = map(int, s.split(sep="/"))
if y > 2019:
    print("TBD")
elif y < 2019:
    print("Heisei")
else:
    if m > 4:
        print("TBD")
    elif m < 4:
        print("Heisei")
    else:
        if d <= 30:
            print("Heisei")
        else:
            print("TBD")


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  int R;
  cin >> R;
  if (R < 1200) {
	  cout << "ABC" << endl;
	} else if (R < 2800) {
	  cout << "ARC" << endl;
	} else {
	  cout << "AGC" << endl;
	}
  return 0;
}


Measured memory_bytes: 256
N = int(input())
abc = []
for i in range(N):
    abc.append(list(map(int, input().split())))

abc[0][0]

ahappiness = [0 for i in range(N)]
bhappiness = [0 for i in range(N)]
chappiness = [0 for i in range(N)]
# syoki
ahappiness[0] = abc[0][0]
bhappiness[0] = abc[0][1]
chappiness[0] = abc[0][2]

#loop
for i in range(1,N):
    ahappiness[i] = max(bhappiness[i-1],chappiness[i-1])+abc[i][0]
    bhappiness[i] = max(ahappiness[i-1],chappiness[i-1])+abc[i][1]
    chappiness[i] = max(ahappiness[i-1],bhappiness[i-1])+abc[i][2]
    
print(max(ahappiness[-1],bhappiness[-1],chappiness[-1]))

Measured memory_bytes: 42520
import math

def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p = map(int, input().split())
a = list(map(int, input().split()))
res = 0

for i in range(n):
  a[i] = a[i]%2

for i in range((a.count(1)+1)//2):
  res = res + comb(a.count(1), 2*i+1)
if res == 0 and p == 0:
  res = 1
res = res * 2**a.count(0)
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  double A;
  double res = 0;
  for (int i = 0; i < N; i++){
    cin >> A;
    res += 1 / A;
  }
  res = 1 / res;
  cout << res;
}

Measured memory_bytes: 384
n,k=map(int,input().split())
a=list(map(int,input().split()))
ca,cb=0,0
mod=10**9+7
for i,x in enumerate(a):
  for j,y in enumerate(a):
    if x>y:
      if i<j:ca+=1
      else:cb+=1
print((ca*k*(k+1)//2%mod+cb*k*(k-1)//2%mod)%mod)

Measured memory_bytes: 70716
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,c,k; cin>>a>>b>>c>>k;
  while(k&&b<=a)
    b*=2, k--;
  while(k&&c<=b)
    c*=2, k--;
  if(c>b&&b>a){
    cout<<"Yes\n";
  }
  else
    cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Add.num;
        var sum = 0;
        for(var i = 1; i <= num; i++)
        {
            sum += i;
            if (sum >= num)
            {
                for(var j = i; j >= 1; j--)
                {
                    if (num - j >= 0)
                    {
                        WriteLine(j);
                        num -= j;
                    }
                    if (num == 0) break;
                }
                return;
            }
        }
    }
}

public class Add
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13268
/*
Author: Deep Chaklasiya
*/

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> data_set;
#define fbo find_by_order
#define ook order_of_key




#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define piiii       pair<pii,pii>
#define viiii       vector<pair<pii,pii>>
#define mi          map<int,int>
#define mii         map<pii,int>
#define piii           pair<int,pair<int,int> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define ef else if





int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }
bool mod(double a,double b) {return a/b - floor(a/b);}

int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}


template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}

void set_min(int &m,int a){
    if(m==-1||m>a)m=a;
}


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int i,j,x,n,m,k,t;
    string s,s1;
    cin>>s>>s1;
    cin>>n>>m;
    string s2;
    cin>>s2;
    if(s2==s)
    {
    	cout<<(n-1)<<" "<<m;
	}
	else cout<<n<<" "<<m-1;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j;
	int a[28];
	for(i=0;i<28;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<31;i++){
		for(j=0;j<28;j++){
			if(i==a[j]){
				break;
			}
			else if(i!=a[j]&&j==27){
				printf("%d\n",i);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main() {
    string s;
    cin >> s;
    if(s == "ABC")cout << "ARC" << ln;
    else cout << "ABC" << ln;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dcm(a) setprecision(a)<<fixed
#define MOD 1000000007
#define clr(memo, a) memset(memo,a,sizeof(memo))
#define PI acos(-1)
int const inf =1e9+5;
void min_self(int & a,int b)
{
    a=min(a,b);
}
int const N=1e2+5;

int v[N];
int w[N];
void solve()
{
int n,W;
cin>>n>>W;
       int sumvalue=0;
    for(int i=0; i<n; i++)
    {
        cin>>w[i];
        cin>>v[i];
        sumvalue+=v[i];
    }
    vector<int> dp(sumvalue+5,inf);
//dp[i] minimu weghit among all value
dp[0]=0;
for(int i=0;i<n;i++)
    for(int j=sumvalue-v[i];j>=0;j--)
    min_self(dp[j+v[i]],dp[j]+w[i]);
int ans=0;
for(int i=0;i<=sumvalue;i++)
    if(dp[i]<=W)
    ans=max(ans,i);
cout<<ans<<endl;
}


int main()
{
    fast;
    solve();

    return 0;
}


Measured memory_bytes: 640
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, D: number, X: number[][] } => {
  const [N, D] = lines[0].split(' ').map(line => +line)
  const X = lines.slice(1, 1 + N).map(line => line.split(' ').map(l => +l))
  const obj = { N, D, X }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { N, D, X } = parseLines(lines)
  let count = 0
  for (let i = 0; i < N; i++) {
    for(let j = i + 1; j < N; j++) {
      let sum = 0
      for (let k = 0; k < D; k++) {
        sum += (X[i][k] - X[j][k]) ** 2
      }
      if (Number.isInteger(Math.sqrt(sum))) {
        count++
      }
    }
  }
  return `${count}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7628
n = int(input())
a = list(map(int,input().split()))

cnt = [0]*(10**5)
c = 0

for i in a:
    if i <= 10**5:
        cnt[i-1] += 1
    else:
        c += 1



for i in range(10**5):
    if cnt[i] > i+1:
        c += cnt[i] - (i+1)
    
    elif cnt[i] < i+1:
        c += cnt[i]

print(c)

Measured memory_bytes: 14212
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		//PrintWriter out=new PrintWriter(System.out);
		Dice D=new Dice();
		List<Integer> dice=new ArrayList<>();
		for(int i=0;i<6;i++)dice.add(in.nextInt());
		char odrs[]=in.next().toCharArray();
		for(int i=0;i<odrs.length;i++)D.turn(odrs[i]);
		System.out.println(dice.get(D.side.get(0)-1));
		//out.flush();
	}
}

class Dice{
	static List<Integer> side=new ArrayList<>(Arrays.asList(1,3,6,4)),vert=new ArrayList<>(Arrays.asList(1,5,6,2));
	
	static void turn(char dist) {
		switch(dist) {
		case 'N':
			int topn=vert.remove(3);
			vert.add(0, topn);
			side.set(0, vert.get(0)); side.set(2, vert.get(2));
			//System.out.println(side+" "+vert);
			break;
			
		case 'E':
			int tope=side.remove(3);
			side.add(0, tope);
			vert.set(0, side.get(0)); vert.set(2, side.get(2));
			//System.out.println(side+" "+vert);
			break;
		
		case 'S':
			int tops=vert.remove(0);
			vert.add(tops);
			side.set(0, vert.get(0)); side.set(2, vert.get(2));
			//System.out.println(side+" "+vert);
			break;
			
		case 'W':
			int topw=side.remove(0);
			side.add(topw);
			vert.set(0, side.get(0)); vert.set(2, side.get(2));
			//System.out.println(side+" "+vert);
			break;
		}	
	}
}



Measured memory_bytes: 26292
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

struct point{
  double x;
  double y;
};

int main()
{
  point p1, p2;
  cin >> p1.x >> p1.y >> p2.x >> p2.y;

  int q;
  cin >> q;
  vector<point> ps;
  for(int i=0; i<q; ++i){
    point temp;
    cin >> temp.x >> temp.y;
    ps.push_back(temp);
  }

  double x2_x1 = p2.x - p1.x;
  double y2_y1 = p2.y - p1.y;

  for(int i=0; i<q; ++i){
    double xp = ps[i].x;
    double yp = ps[i].y;
    double ansx = ((yp-p1.y)*x2_x1*y2_y1+xp*x2_x1*x2_x1+p1.x*y2_y1*y2_y1)/ \
      (y2_y1*y2_y1 + x2_x1*x2_x1);
    double ansy = -((yp-p1.y)*x2_x1*x2_x1+(p1.x-xp)*y2_y1*x2_x1)/ \
      (y2_y1*y2_y1+x2_x1*x2_x1) + yp;

    cout << fixed;
    cout << setprecision(10) <<  ansx << " "
	 << setprecision(10) <<  ansy << "\n";
  }
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

using namespace std;
typedef long long ll;
typedef pair <int,pair <int,int > > pii;

const int MOD = 1000000007;
map <int,int> mp;
int main()
{
    ll a,b,c,ok = 0;
    cin >> a >> b >> c;
    if(a == b && c != a){
        ok = 1;
    }
    if(c == b && c != a){
        ok = 1;
    }
    if(a == c && b != a){
        ok = 1;
    }
    if(ok)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

ll count(string s) {
  ll cnt = 0, len = s.length();
  rep(i,len-1) {
    if (s[i] == s[i+1]) {
      s[i+1] = '_';
      cnt++;
    }
  }
  return cnt;
}

int main() {
  string s; in(s);
  ll k, ans = INFL; in(k); k;
  string s1 = s, s2 = s+s, s3 = s+s+s;
  ll cnt1 = count(s1);
  ll cnt2 = count(s2);
  ll cnt3 = count(s3);
  cnt3 -= cnt2;
  cnt2 -= cnt1;
  ans = cnt1 + k/2*cnt2 + (k-1)/2*cnt3;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
int h,w,i,t;
while(1){
scanf("%d %d",&h,&w);
if(h==0&&w==0)break;
for(i=1;i<h+1;i++){
for(t=1;t<w+1;t++){
if(i==1||i==h)printf("#");
else if(t==1||t==w)printf("#");
else printf(".");
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
#include <iostream>
int main()
{
  int a[5];
  for(int i = 0; i< 5; i++){std::cin >> a[i];}
  int k;std::cin >> k;
  for(int i = 0; i< 5; i++){
    for(int j = 0; j< 5; j++){
      if(a[i]-a[j]<= k and a[i]-a[j]>= -k){}
      else{return std::cout << ":("<<std::endl, 0;}
    }
  }
  std::cout << "Yay!"<<std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		while(true){
			String str = br.readLine();
			StringTokenizer st = new StringTokenizer(str, " ");
			int H = Integer.parseInt(st.nextToken());
			int W = Integer.parseInt(st.nextToken());

			if(H == 0 && W == 0){
				break;
			}

			for ( int i = 0; i < H; i++ ){
				for ( int j = 0; j < W; j++ ){
					if (i % 2 == 1 && j % 2 == 1) {
						System.out.print("#");
					} else if (i % 2 == 1 && j % 2 == 0) {
						System.out.print(".");
					} else if (i % 2 == 0 && j % 2 == 1) {
						System.out.print(".");
					} else if (i % 2 == 0 && j % 2 == 0) {
						System.out.print("#");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}



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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  a=a+b;
  b=a-b;
  a=a-b;
  a=a+c;
  c=a-c;
  a=a-c;
  cout<<a<<" "<<b<<" "<<c<<endl;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

ll pCount(int x){
  if(x==0) return 1;
  return pCount(x-1)*2 + 1;
}

ll allCount(int x){
  if(x==0) return 1;
  return allCount(x-1)*2 + 3;
}


signed main() {
  int n,k;
  cin >> n >> k;
  k--;
  vector<int> pos(n);
  for(int i=0;i<n;i++){
    cin >> pos[i];
  }
  
  int minDist = 1000000000;
  for(int i=0;i<n-k;i++){
    if((pos[i]<=0 && pos[i+k]<=0)
      ||(pos[i]>=0 && pos[i+k]>=0)){
      minDist = min(minDist, (abs(pos[i])>abs(pos[i+k]))?abs(pos[i]):abs(pos[i+k]));
    }
    else if(pos[i]<=0 && pos[i+k]>=0){
      if(abs(pos[i]) < pos[i+k]){
        minDist = min(minDist, abs(pos[i])*2+pos[i+k]);
      }
      else{
        minDist = min(minDist, pos[i+k]*2+abs(pos[i]));
      }
    }
  }
  
  cout << minDist << endl;
  
  
  return 0;
}



Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	int n;
  cin>>n;
  vector<int>a(n);
  map<int,int>mp;
  rep(i,n)cin>>a[i];
  vector<bool>b(1e6+5);
  sort(all(a));
  rep(i,n){
    mp[a[i]]++;
    if(mp[a[i]]>=2)continue;
    if(b[a[i]])continue;
    for(int j=a[i]+a[i];;j+=a[i]){
      if(j>1e6)break;
      b[j]=true;
    }
  }
  int ans=0;
  rep(i,n){
    if(mp[a[i]]>=2)continue;
    if(b[a[i]])continue;
    ++ans;
  }
  cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 13432
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuilder str = new StringBuilder();
		int pointer = 0;
		for (int i = 0; i < s.length(); i++) {
			switch (s.charAt(i)) {
			case '0':
				str.append('0');
				pointer++;
				break;
			case '1':
				str.append('1');
				pointer++;
				break;
			case 'B':
				if(pointer == 0){
					break;
				}
				str.deleteCharAt(pointer -1);
				pointer--;
				break;
			default:
				break;
			}
		}
		System.out.println(str.toString());
		sc.close();
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  int n, h, w, ans = 0, a, b;
  scanf("%d %d %d", &n, &h, &w);
  for(int i = 0; i < n; ++i){
    scanf("%d %d", &a, &b);
    if(a >= h && b >= w) ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,j,x=0;
  cin>>m;
  vector<int> v(m);
  for(j=0;j<m;j++){
    cin>>v.at(j);
    x+=v.at(j);
  }
  if(x%10>0) cout<<x<<endl;
  else{
    sort(v.begin(),v.end());
    for(j=0;j<m;j++){
      if(v.at(j)%10>0){
        cout<<x-v.at(j)<<endl;
        return 0;
      }
    }
    cout<<0<<endl;
  }
}

Measured memory_bytes: 3556
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[0]*(n+1)
    m=0
    for i in range(n,0,-1):
        k=n//i
        if k==1:
            b[i]=a[i-1]
        else:
            s=0
            for j in range(2,k+1):
                s+=b[i*j]
            b[i]=(s+a[i-1])%2
    ans=[]
    for i in range(1,n+1):
        if b[i]==1:
            ans.append(i)
    print(sum(b))
    if len(ans)!=0:
        print(' '.join(map(str,ans)))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 19892
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;

int main()
{
	vector<int> p;
	for(int i = 0; i < 2; i++){
		priority_queue<int> point;
		for(int j = 0; j < 10; j++){
			int buf;
			cin>>buf;
			point.push(buf);
		}
		int res = 0;
		for(int j = 0; j < 3; j++){
			res += point.top();
			point.pop();
		}
		p.push_back(res);
	}
	cout << p[0] << " " << p[1] <<endl;
}

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

ll mod=1e9+7;
ll dp[200100];
ll last[200100];

int main(){
	int n; cin >> n;
	vector<int> c(n);
	dp[0]=1;
	for(int i=0;i<n;i++){
		cin >> c[i];
		if(last[c[i]]&&last[c[i]]<i){
			(dp[i+1]+=dp[last[c[i]]])%=mod;
		}
		(dp[i+1]+=dp[i])%=mod;
		last[c[i]]=i+1;
	}
	cout << dp[n]%mod << endl;
}

Measured memory_bytes: 4096
#include<iostream>
#define SETMINTAL 2000000000
using namespace std;

int cnt=0;
int L[250005],R[250005];

void myMerge(int A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    int i,j;
    for(int i=0;i<n1;i++){
        L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++){
        R[i]=A[mid+i];
    }
    L[n1]=R[n2]=SETMINTAL;
    i=0; j=0;
    for(int k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
    }
}

void MergeSort(int A[],int left,int right){
    int mid=0;
    if(left+1<right){
        mid=(right+left)/2;
        MergeSort(A,left,mid);
        MergeSort(A,mid,right);
        myMerge(A,left,mid,right);
    }
}

int main(){
    int A[500005];
    int n;
    cin>>n;
    cnt=0;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    MergeSort(A,0,n);
    for(int i=0;i<n;i++){
        if(i) cout<<' ';
        cout<<A[i];
    }
    cout<<endl<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 6992
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int n;cin>>n;
	int a=n/1000,b=(n/100)%10,c=(n/10)%10,d=n%10;
	rep(i,8) {
		string ans=to_string(a);
		int t=a;
		if(i&0b100) {t+=b;ans+="+";}
		else {t-=b;ans+="-";}
		ans+=to_string(b);
		if(i&0b10) {t+=c;ans+="+";}
		else {t-=c;ans+="-";}
		ans+=to_string(c);
		if(i&0b1) {t+=d;ans+="+";}
		else {t-=d;ans+="-";}
		ans+=to_string(d)+"=7";
		if (t==7) {cout<<ans<<endl;return 0;}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iterator>

using namespace std;

int main(){
    int N,Y,k;
    bool flag=false;
    cin>>N>>Y;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
            k=N-i-j;
            if(Y==10000*i+5000*j+1000*k){
                flag=true;
                cout<<i<<" "<<j<<" "<<k;
                break;
            }
        }
        if(flag)break;
    }
    if(!flag)cout<<-1<<" "<<-1<<" "<<-1;
}

Measured memory_bytes: 3640