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

using namespace std;

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

	int result;

	if(X >= 400 && X <= 599) {
		result = 8;
	} else if(X >= 600 && X <= 799) {
		result = 7;
	} else if(X >= 800 && X <= 999) {
		result = 6;
	} else if(X >= 1000 && X <= 1199) {
		result = 5;
	} else if(X >= 1200 && X <= 1399) {
		result = 4;
	} else if(X >= 1400 && X <= 1599) {
		result = 3;
	} else if(X >= 1600 && X <= 1799) {
		result = 2;
	} else {
		result = 1;
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3620
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0

n = iin()
a = [int(x) for x in input().split()]
b = [0] * n
for i in range(n):
    b[a[i]-1] = i + 1

for i in range(n):
    print(b[i],end=' ')

Measured memory_bytes: 14024
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define F first
#define S second
using namespace std;
vector<bool> A[12];
int r,c,k,ans = INT_MAX;
void solve(vector<int> v){
//	return ;
	v.pb(r);
	int e = 0;
	vector<int> X(v.size() + 10),Y(v.size()+10);
	for (int i = 0; i < c; i++){
		for (int j = 0; j < v.size()-1; j++){
			for (int t = v[j]; t < v[j+1]; t++){
				Y[j] += (A[t][i]);						
			}
		}
		for (int j  = 0; j < v.size()-1; j++)
			if (Y[j] > k) return;
		bool flag = 1;        
		for (int j = 0; j < v.size()-1; j++){
			if (X[j] + Y[j] > k)
				flag = 0;	
		}
		if (flag == 0){
			for (int j = 0; j < v.size()-1; j++)
			X[j] = 0,Y[j] = 0;
			i--;
			e++;
		}
		else {
		for (int j = 0; j < v.size()-1; j++)
		X[j] += Y[j],Y[j] = 0;
		}
	}
	ans = min(ans,e + (int)v.size() - 2);
}	
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> r >> c >> k;
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j ++){
			char e;
			cin >> e;
			A[i].pb(e == '1');			
		}
	}
	int g = (1 << (r-1));
	for (int i = 0; i < g; i++){
		vector<int> v;
		v.pb(0);
		for (int h = 0; (1 << h) <= i; h++){
			if ((1 << h) & i)
				v.pb(h+1);
			}
		solve(v);			
	}
	cout << ans;
		
	
	
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int Q1 = x / 500;
        x = x % 500;
        int Q2 = x / 5;
        int result = (Q1 * 1000) + Q2 * 5;
        System.out.println(result);
    }
}


Measured memory_bytes: 35672
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    cout << 700 + (s[0] == 'o' ? 100 : 0) + (s[1] == 'o' ? 100 : 0) + (s[2] == 'o' ? 100 : 0) << endl;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
   int n;
   cin >> n;
   set<int> s;
   while(n--)
   {
       int a;
       cin >> a;
       s.insert(a);
   }

   if(s.size() % 2 == 0)
   {
       cout << s.size() - 1 << endl;
   }
   else
   {
       cout << s.size() << endl;
   }


}


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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int64_t M = 1e9+7;

vector<int64_t> inv_tbl(2000000);

int64_t modpow(int64_t n, int64_t m) {
    if (m == 0) return 1;
    else if (m % 2 == 0) { 
        int64_t r = modpow(n, m / 2);
        return (r * r) % M;
    } else {
        int64_t r = modpow(n, m / 2);
        return ((n * r) % M * r) % M;
    }
}

int64_t inv(int n) {
    return inv_tbl[n];
}

void compute_inv() {
    for (size_t i = 0; i < inv_tbl.size(); ++i) {
        inv_tbl[i] = modpow(i, M - 2);
    }
}

int64_t comb(int n, int k) {
    int64_t c = 1;
    for (int i = 1; i <= k; ++i) {
        c = (((n - i + 1) * inv(i)) % M * c) % M;
    }
    return c;
}

int64_t H(int64_t n, int64_t m) {
    return comb(n - 1 + m, m);
}

int main() {
    compute_inv();
    int n, k;
    cin >> n >> k;
    int64_t res = 0;
    vector<int64_t> comb_n(n + 1);
    comb_n[0] = 1;
    for (int i = 1; i <= n; ++i) {
        comb_n[i] = ((comb_n[i - 1] * (n - i + 1)) % M * inv(i)) % M;
        /* cout << "comb(" << n << ", " << i << ") = " << comb_n[i] << endl; */
    }
    vector<int64_t> comb_n1(n);
    comb_n1[0] = 1;
    for (int i = 1; i < n; ++i) {
        comb_n1[i] = ((comb_n1[i - 1] * (n - 1 - i + 1)) % M * inv(i)) % M;
     /*    cout << "comb(" << n - 1 << ", " << i << ") = " << comb_n[i] << endl; */
    }

    for (int i = 0; i <= min(n - 1, k); ++i) {
        res = (res + (comb_n[i] * comb_n1[i]) % M) % M;
    }
    cout << res << endl;
}

Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9){
    cout << "hon" << endl;
  }else if(n%10==0||n%10==1||n%10==6||n%10==8){
    cout << "pon" << endl;
  }else{
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3592
from collections import deque
import sys, copy, itertools,heapq
input = sys.stdin.readline

n = int(input())
MAP = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
  MAP[i][i]=10**9


ans = 0
for i in range(n):
  for j in range(i+1,n):
    MAPP=[0]*n
    for k in range(n):
      MAPP[k]=MAP[i][k]+MAP[j][k]
    d = min(MAPP)
    if MAP[i][j] < d:
      ans += MAP[i][j]
    elif d < MAP[i][j]:
      print(-1)
      exit()
  
#print(MAP)
print(ans)

Measured memory_bytes: 75780
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int n;cin>>n;
	int a[n],sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum^=a[i];
	}
	vector<int>vec;
	for(int i=0;i<n;i++)
	{
		int y=sum^a[i];
		vec.push_back(y);
	}
	for(auto u:vec)
	cout<<u<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 6864
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[N];
        int ans = 0;

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
        }

        loop:for(int i=0; i<=30; i++){
            for(int j=0; j<N; j++){
                if(A[j]%2!=0){
                    System.out.println(ans);
                    break loop;
                }
                else if(A[j]%2==0){
                    A[j] = A[j] / 2;
                }
                if(j==N-1){
                    ans += 1;
                }
            }
        }
    } 
}

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

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

	int l,r;

	cin >> l >> r;

	if(l/2019 < r/2019)
	{
		cout << 0 << '\n';
	}
	else
	{
		int res = 1e9;
		l%=2019;
		r%=2019;
		for(int i=l;i<=r;i++)
		{
			for(int j=i+1;j<=r;j++)
			{
				res = min(res,((i*j)%2019));
			}
		}
		cout << res << '\n';
	}
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N;
  int flag = 0;
  scanf("%d",&N);

  if(N/10 == 9) flag = 1;
  if(N%10 == 9) flag = 1;
  
  if(flag) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int check[1000100];
int main(){
    cin >> n >> m >> k;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=m;j++)
            check[(n-i)*j+(m-j)*i] = 1;
    if(check[k]) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 4096
import math
import itertools
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i],y[i] = [int(j) for j in input().split()]
# print(n,x,y)
dict = {}
for i in range(n):
    for j in range(n):
        if i < j:
            dict[str(i)+str(j)] = math.sqrt((x[i] - x[j])**2 + (y[i]- y[j])**2)

# print(dict)
# perm = [n for n in range(n)]
# print(perm)
sumation = 0
# print(len([v for v in itertools.permutations(perm,n)]))
# for p for perm:
#     for i in p: #それぞれのまち
#         if i == 0:
#             continue
#         else:
#             sum
# list = [v for v in dict.values()]
# # print(type(list))
# sumation = sum(list)
# # print(sumation)
# sumation = sumation * math.factorial(n)
# # print(sumation)
# for kei, length in dict.items():
#     if n != 2:
#         sumation -= length*2*math.factorial(n-2)
#     else:
#         continue
# # print(sumation)
# print(sumation/math.factorial(n))
for kei,length in dict.items():
    sumation += (n-1) * math.factorial(n-2)*length*2
print(sumation/math.factorial(n))


Measured memory_bytes: 3064
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() { 
  char c;
  cin>>c;

  cout<<++c<<endl;
}



Measured memory_bytes: 256
let S = readLine()!.characters
var ans = (0..<S.count).map{_ in 0}
var a = [0, 0]
for (i, c) in S.enumerate() {
    if c == "R" {
        a[i%2]++
    } else {
        ans[i] += a[i%2]
        ans[i-1] += a[(i%2)^1]
        a = [0, 0]
    }
}
for (i, c) in S.enumerate().reverse() {
    if c == "L" {
        a[i%2]++
    } else {
        ans[i] += a[i%2]
        ans[i+1] += a[(i%2)^1]
        a = [0, 0]
    }
}
print(ans.map{String($0)}.joinWithSeparator(" "))

Measured memory_bytes: 9308
package main

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

func main() {
	H, W, D := ReadInt(), ReadInt(), ReadInt()
	toID := func(x, y int) int {
		return y*W + x
	}
	toXY := func(id int) (int, int) {
		return id % W, id / W
	}
	valToID := make([]int, H*W)
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			valToID[ReadInt()-1] = toID(x, y)
		}
	}

	s := make([]int, H*W+1)
	for val := D; val < H*W; val++ {
		prevVal := val - D
		x, y := toXY(valToID[val])
		prevX, prevY := toXY(valToID[prevVal])
		s[val] = s[prevVal] + Abs(x-prevX) + Abs(y-prevY)
	}

	Q := ReadInt()
	for q := 0; q < Q; q++ {
		L, R := ReadInt()-1, ReadInt()-1
		fmt.Println(s[R] - s[L])
	}
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

var reader = bufio.NewReader(os.Stdin)

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


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

int main() {
    int n;
    cin >> n;
    vector<int> data(n);

    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }

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

    int count = 0;
    
    for (int i = 0; i < n - 2; i++){
        for (int j = i + 1; j < n - 1; j++){
            int num = data.at(i) + data.at(j);
            auto itr = lower_bound(data.begin(), data.end(), num);
            int dist = distance(data.begin(), itr);
            if (dist > j){
                count += dist - j - 1;
            }
        }
    }

    cout << count << endl;
}

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

const int N = 1e5 + 5;

string s;
string res = "";
int k;

int main() {
	cin >> s >> k;
	for (int i = 0; i < s.size(); ++i) {
		int c = s[i] - 'a';
		int dis = (26 - c) % 26;
		if (i == s.size() - 1) {
			k %= 26;
			while(k--) c = (c + 1) % 26;
			res += (char)(c + 'a');
			cout << res << endl;
			return 0;
		}

		if (k >= dis) {
			k -= dis;
			res += 'a';
		} else {
			res += (char)(c + 'a');
		}
	}
}

Measured memory_bytes: 640
/*  -*- coding: utf-8 -*-
 *
 * 3066.cc: Satake likes straight
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 9;
const int NBITS = 1 << MAX_N;
const double PI = acos(-1.0);
const double DINF = 1e60;

/* typedef */

template <typename T>
struct Pt {
  T x, y;

  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt<T> &pt) : x(pt.x), y(pt.y) {}

  Pt<T> operator+(const Pt<T> pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt<T> pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt<T> v) const { return x * v.x + y * v.y; }
  T cross(Pt<T> v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt<T> pt) { return Pt<T>((x + pt.x) / 2, (y + pt.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }

  Pt<T> normalize() {
    double d0 = d();
    return (d0 != 0.0) ? Pt<T>(x / d0, y / d0) : *this;
  }

  void print() { printf("(%d,%d)", x, y); }
};

typedef Pt<double> pt;

/* global variables */

pt ps[MAX_N], nvs[MAX_N][MAX_N];
double dp[NBITS][MAX_N][MAX_N];

/* subroutines */

inline void setmin(double &a, double b) { if (a > b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);
  n++;

  ps[0] = pt(0.0, 0.0);
  for (int i = 1; i < n; i++) scanf("%lf%lf", &ps[i].x, &ps[i].y);

  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j)
	nvs[i][j] = (ps[j] - ps[i]).normalize();

  int nbits = 1 << n;
  for (int bits = 0; bits < nbits; bits++)
    for (int i = 0; i < n; i++)
      fill(dp[bits][i], dp[bits][i] + n, DINF);

  for (int i = 1, bi = 1 << 1; i < n; i++, bi <<= 1)
    dp[1 | bi][0][i] = acos(nvs[0][i].x);

  for (int bits = 0; bits < nbits; bits++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
	if (dp[bits][i][j] < DINF)
	  for (int k = 0, bk = 1; k < n; k++, bk <<= 1)
	    if (! (bits & bk))
	      setmin(dp[bits | bk][j][k],
		     dp[bits][i][j] + acos(nvs[i][j].dot(nvs[j][k])));

  double mind = DINF;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (dp[nbits - 1][i][j] < DINF)
	setmin(mind, dp[nbits - 1][i][j] + acos(nvs[i][j].dot(nvs[j][0])));

  printf("%.8lf\n", mind * 180 / PI);
  return 0;
}



Measured memory_bytes: 3764
import sys
from collections import deque

W,H,C = None,None,None
mmax = None

def main():
    global W,H,C,mmax

    while True:
        W,H = map(int,input().split())
        if not W and not H:
            return
        C = []
        mmax = [[-1]*(W+1) for _ in range(H+1)]
        for _ in range(H):
            C.append(list(input()))
        # visualize(C)

        num = 0

        # for i in range(H):
        #     for j in range(W):
        #         if mmax[i][j] != -1:
        #             continue
        #         print("------", i, j, "--------")
        #         num = max(num, bfs(i,j))

        for i in reversed(range(H)):
            for j in reversed(range(W)):
                if mmax[i][j] != -1:
                    continue
                num = max(num, bfs(i,j))
        
        print(num)


def bfs(y,x):
    global W,H,C,mmax

    if not C[y][x].isdigit():
        return 0

    l = []
    queue = deque(l)
    dd = [(0,-1), (-1,0)]
    num = 0

    queue.appendleft((C[y][x],(y,x)))
    mmax[y][x] = int(C[y][x])

    while len(queue) != 0:
        s, (uy,ux) = queue.pop()
        for dy,dx in dd:
            vy,vx = uy+dy, ux+dx
            if not (0 <= vy < H and 0 <= vx < W):
                num = max(num, mmax[uy][ux])
                continue
            if C[vy][vx].isdigit():
                n = int(C[vy][vx]+s)
                if mmax[vy][vx] < n:
                    queue.appendleft((C[vy][vx]+s, (vy,vx)))
                    mmax[vy][vx] = n
            else:
                num = max(num, mmax[uy][ux])

    return num


# def bfs(y,x): # h w
#     global W,H,C,mmax

#     if not C[y][x].isdigit():
#         return 0

#     l = []
#     queue = deque(l)
#     dd = [(0,1), (1,0)]
#     num = 0

#     queue.appendleft((C[y][x],(y,x)))
#     mmax[y][x] = int(C[y][x])

#     while len(queue) != 0:
#         print(len(queue))
#         s, (uy,ux) = queue.pop()
#         for dy,dx in dd:
#             vy,vx = uy+dy, ux+dx
#             if not (0 <= vy < H and 0 <= vx < W):
#                 num = max(num, mmax[uy][ux])
#                 continue
#             if C[vy][vx].isdigit():
#                 n = int(s+C[vy][vx])
#                 if mmax[vy][vx] < n:
#                     queue.appendleft((s+C[vy][vx], (vy,vx)))
#                     mmax[vy][vx] = n
#             else:
#                 num = max(num, mmax[uy][ux])

#     return num


def visualize(mmap):
    for row in mmap:
        print(" ".join(row))

            

if __name__ == '__main__':
    main()


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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	long long int n, k;
	long long int res = 0;
 
	cin >> n >> k;
 
	if (k == 0)
	{
		cout << n * n << '\n';
		return 0;
	}
 
	for (long long int i = k + 1; i <= n; i++)
	{
		long long int x = n/i;
		long long int y = n%i;
		long long int a = k;
		long long int b = i - 1;

		if(y<a)
		{
			res += (x)*(b-a+1);
		}
		else
		{
			res += (x+1)*(y-a+1);
			res += (x)*(b-y);
		}
	}
 
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int x, a;
    cin >> x >> a;
    if(x >= a) cout << 10 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i == 0 or i == H - 1:
            print('#'*W)
        else:
            print('#' + '.'*(W - 2) + '#')
    print()


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

int main() {
  string a,b,c; cin >> a >> b >> c;
  if (a.back() == b.front() && b.back() == c.front()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

int main()
{
  int n;
  int sum = 0;
  cin >> n;
  int v[n], c[n];
  for (int i = 0; i < n; i++){
    cin >> v[i];
  }
  for (int i = 0; i < n; i++){
    cin >> c[i];
  }
  for (int i = 0; i < n; i++){
    sum = max(sum, sum + v[i] - c[i]);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char c[1001][1001];
long long a[1001][1001];
int main()
{
	long long i,j,n,m,h,w;
	scanf("%lld %lld",&h,&w);
	a[1][1]=1;
	for(i=1;i<=h;i++)
	{
		getchar();
		for(j=1;j<=w;j++)
		{
			scanf("%c",&c[i][j]);
		}
	}
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			if(c[i][j]!='#')
			{
				a[i][j]=(a[i][j]+a[i-1][j]+a[i][j-1])%1000000007;
			}
		}
	}
	printf("%lld",a[h][w]);
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int A,B,C;cin>>A>>B>>C;
  	int z=0;
  	if(A==0)z=1;
    if(A!=0)A--;
    int d=B/C;
    int e=A/C;
    cout<<d-e+z<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def get_parent(index):
    return index // 2


def get_left(index):
    return 2 * index


def get_right(index):
    return get_left(index) + 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    array.insert(0, None)
    for i in range(1, array_length + 1):
        parent, left, right = get_parent(i), get_left(i), get_right(i)
        print('node ' + str(i) + ': ', end='')
        print('key = ' + str(array[i]) + ',', end='')
        if parent:
            print(' parent key = ' + str(array[parent]) + ',', end='')
        if left <= array_length:
            print(' left key = ' + str(array[left]) + ',', end='')
        if right <= array_length:
            print(' right key = ' + str(array[right]) + ',', end='')
        print(' ')

Measured memory_bytes: 7764
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){
	int i,j,k;
	int n1=mid-left;
	int n2=right-mid;
	for(i=0;i<n1;i++)L[i]=A[left+i];
	for(i=0;i<n2;i++)R[i]=A[mid+i];
	L[n1].value=R[n2].value=SENTINEL;
	i=j=0;
	for(k=left;k<right;k++){
		if(L[i].value<=R[j].value)A[k] = L[i++];
		else A[k] = R[j++];
	}
}

void mergeSort(struct Card A[], int n, int left, int right)
{
	int mid;
	
	if(left+1<right){
		mid=(left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int partition(struct Card A[], int n, int p, int r){
	int i, j;
	struct Card t, x;
	x=A[r];
	i=p-1;
	for(j=p; j<r; j++){
		if(A[j].value <= x.value){
			i++;
			t=A[i];
			A[i]=A[j];
			A[j]=t;
		}
	}
	t=A[i+1];
	A[i+1]=A[r];
	A[r]=t;
	return i+1;
}


void quickSort(struct Card A[], int n, int p, int r){
	int q;
	if(p<r){
		q=partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(void)
{
	int n,i,v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable=1;
	
	scanf("%d",&n);
	
	for(i=0; i<n; i++){
		scanf("%s %d",S,&v);
		A[i].suit=B[i].suit=S[0];
		A[i].value=B[i].value=v;
	}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i=0;i<n;i++){
		if(A[i].suit!=B[i].suit)stable=0;
	}
	
	if(stable==1)printf("Stable\n");
	else printf("Not stable\n");
	for(i=0;i<n;i++){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}




Measured memory_bytes: 4196
#include <iostream>

using namespace std;

int main()
{
  int A,B ;
  cin >>A>>B ;
if (A==B) cout <<"Draw";
 if (A>B || A==1 ) {
        if (B!=1) cout<<"Alice" ; }

if (B>A || B==1) {
        if (A!=1 ) cout <<"Bob" ; }


    return 0;
}


Measured memory_bytes: 384
s = input()
n = len(s)
m = 2019

a = 0
r = [0 for _ in range(m+1)]
r[0] = 1
z = 0
j = 1
for i in range(0,n):
    j = j * 10 % m
    ss = int(s[n-i-1])*j + z
    z = ss%m



    a += r[z]
    r[z] += 1

print(a)


Measured memory_bytes: 9228
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define lson (k<<1)
#define rson (k<<1)+1
const int mod = 1e9+7;
const int maxn = 2e5+6;
const double eps = 1e-6;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
struct P{
	int x,id,b;
}a[maxn];
bool cmp1(P t,P s){
	return t.x<s.x;
}
bool cmp2(P t,P s){
	return t.id<s.id;
}
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",&a[i].x),a[i].id=i;
	sort(a+1,a+n+1,cmp1);
	rep(i,1,n+1){
		int m = n/2 + 1;
		if(i<m) a[i].b = a[m].x;
		else a[i].b = a[m-1].x;
	}
	sort(a+1,a+n+1,cmp2);
	rep(i,1,n+1) printf("%d\n",a[i].b);
	return 0;
}


Measured memory_bytes: 4480
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
///////////////////////////////////////



int main() {
	string a, b;
	int A, B;
	string c;
	cin >> a >> b;
	cin >> A >> B;
	cin >> c;
	if (a == c) {
		cout << A - 1 << " " << B << endl;
	}
	else {
		cout << A << " " << B - 1 << endl;
	}
	return 0;
}

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

int intersections(double dDist, int nR1, int nR2) {
    if (dDist > nR1 + nR2)  { return 4; }
    if (dDist == nR1 + nR2) { return 3; }
    if (dDist > nR2 - nR1)  { return 2; }
    if (dDist == nR2 - nR1) { return 1; }
    if (dDist < nR2 - nR1)  { return 0; }
    return -1;
}

double dist(double dC1x, double dC1y, double dC2x, double dC2y) {
    return sqrt(pow((dC2x - dC1x), 2) + pow((dC2y - dC1y), 2));
}

int main()
{
    double dC1x, dC1y, dC2x, dC2y;
    int  nC1r, nC2r;
    cin >> dC1x >> dC1y>> nC1r >> dC2x >> dC2y >> nC2r;
    double dDist = dist(dC1x, dC1y, dC2x, dC2y);
    int nAns = nC1r < nC2r ? intersections(dDist, nC1r, nC2r) : intersections(dDist, nC2r, nC1r);
    cout << nAns << '\n';
    return 0;
}




Measured memory_bytes: 3200
#エラトステネスの篩
MAX_NUM = 999999
primes = []
max = Math.sqrt(MAX_NUM).ceil
#arr = [*2..MAX_NUM]
arr = Array.new(MAX_NUM){|i| i.even? ? nil : i}              
arr[0..2] = [nil, nil, 2]
0.upto(max) {|i|
  next if arr[i] == nil
  primes << arr[i]
  #偶数は処理済みなので1つ飛ばしで篩を行う
  i.step(arr.length, primes.last * 2){|j| arr[j] = nil}
}
primes.concat(arr.compact!)
#Prime Number
while gets
  n = $_.to_i
  puts primes.take_while{|i| i <= n}.length
end

Measured memory_bytes: 13892
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int id[100010][30];
char s[100010],t[100010];
int pre[30];
int main(){
	scanf("%s%s",s,t);
	ll n=strlen(s);
	rep(i,0,26)pre[i]=-1;
	rep(i,0,n)rep(j,0,26)id[i][j]=-1;
	
	rep(_,0,2)for(int i=n-1;i>=0;i--){
		rep(j,0,26)id[i][j]=pre[j];
		pre[s[i]-'a']=i;
	}
	ll cnt=-1,pos=n-1;
	ll m=strlen(t);
	rep(i,0,m){
		int nx=id[pos][t[i]-'a'];
		if(nx==-1){
			puts("-1");
			return 0;
		}
		if(nx<=pos)cnt++;
		pos=nx;
	}
	printf("%lld",cnt*n+pos+1);
}

Measured memory_bytes: 12032
r, g, b, n = gets.strip.split.map(&:to_i)

ans = 0
(0..n).each do |i|
    (0..n).each do |j|
        rest = n - (r * i + g * j)
        if rest >= 0 && rest % b == 0 && rest / b <= 3000
            ans += 1
        end
    end
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 101, M = 2e5 + 1;
int64_t n, W, a[N], w[N], dp[M];

int main(int argc, char** argv)
{
#ifdef LOCAL
  freopen(strcat(argv[0], ".in"), "ab+", stdin);
#endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  cin >> n >> W;
  for (int i = 0; i < n; i++) cin >> w[i] >> a[i];

  dp[0] = -1;
  
  for (int k = 0; k < n; k++)
    for (int x = W; x >= 0; x--)
      if (dp[x]) dp[x + w[k]] = max(dp[x + w[k]], dp[x] + a[k] + (x == 0));

  cout << *max_element(dp, dp + W + 1) << endl;
  
  return 0;
}


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

int main()
{
	int n, w, h, x, y, s, t, c, maxi;

	while (cin >> n , n) {
		cin >> w >> h;
		bool m[w][h];
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h; j++) {
				m[i][j] = false;
			}
		}
		
		while (n--) {
			cin >> x >> y;
			m[x - 1][y - 1] = true; 
		}
		
		cin >> s >> t;
		maxi = 0;

		for (int i = 0;  i + s - 1 < w; i++) {
			for (int j = 0; j + t - 1 < h; j++) {
				c = 0;
				for (int k = i; k < i + s; k++) {
					for (int l = j; l < j + t; l++) {
						if (m[k][l]) c++;
					}
				}
				maxi = max(maxi, c);
			}
		}
		
		cout << maxi << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;

ll sum[500010];

int main() {
    int n;
    cin >> n;
    cout << (1000-n%1000)%1000 << endl;
    return 0;
}

Measured memory_bytes: 3644
#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 - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

    string s;
    cin >> s;
    ll n = s.size();
    vll a;
    REP(i, n){
        if(s[i] == 'A') a.push_back(0);
        else if(i < n - 1 && s[i] == 'B' && s[i + 1] == 'C'){
            a.push_back(1);
            i++;
        }
        else a.push_back(2);
    }
    ll k = a.size();
    ll cnt = 0, res = 0;
    REP(i, k){
        if(a[i] == 0) cnt++;
        else if(a[i] == 1) res += cnt;
        else cnt = 0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2700
#define _USE_MATH_DEFINES
 #define INF 100000000
 #include <iostream>
 #include <cstdio>
 #include <sstream>
 #include <cmath>
 #include <cstdlib>
 #include <algorithm>
 #include <queue>
 #include <stack>
 #include <limits>
 #include <map>
 #include <string>
 #include <cstring>
 #include <set>
 #include <deque>
 #include <bitset>
 #include <list>

 using namespace std;

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

 static const double EPS = 1e-8;

int hour2second(int h,int m,int s){
  return h*60*60+m*60+s;
}

int main(){
   int n;
   while(~scanf("%d",&n)){
     if(n==0) break;

     vector<int> departure_times;
     vector<int> arrive_times;
     for(int i=0;i<n;i++){
       //hh:mm:ss hh:mm:ss 
       int hh[2],mm[2],ss[2];
       scanf("%d:%d:%d %d:%d:%d",
	     hh,mm,ss,hh+1,mm+1,ss+1);
       int departure_second = hour2second(hh[0],mm[0],ss[0]);
       int arrive_second = hour2second(hh[1],mm[1],ss[1]);

       departure_times.push_back(departure_second);
       arrive_times.push_back(arrive_second);
     }
     sort(departure_times.begin(),departure_times.end());
     sort(arrive_times.begin(),arrive_times.end());
     
     int dep_idx = 0;
     int res = 0;
     int count = 0;     
     for(int arv_idx=0;arv_idx<arrive_times.size();arv_idx++){
       while(dep_idx<departure_times.size()){
	 if(departure_times[dep_idx] < arrive_times[arv_idx]){
	   count++;
	   dep_idx++;
	   res = max(res,count);
	 }
	 else{
	   count--;
	   break;
	 }
       }
     }
     printf("%d\n",res);
   }
}

Measured memory_bytes: 1336
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <typeinfo>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;



int main()
{
	int N;
	cin >> N;
	vi t(N + 1, 0), x(N + 1, 0), y(N + 1, 0);
	repr(i, 1, N + 1) {
		cin >> t[i] >> x[i] >> y[i];
	}
	bool ans = true;

	rep(i, N)
	{
		int time = t[i + 1] - t[i];
		int xx = x[i + 1] - x[i];
		int yy = y[i + 1] - y[i];

		if ((time - xx - yy) % 2 == 0 && time >= xx + yy)
		{
		}
		else
		{
			ans = false;
			break;
		}
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	

	return 0;
}


Measured memory_bytes: 1408
# coding=utf-8


def making_n(usable_numbers: int, target: int) -> int:
    if usable_numbers == 1:
        if 0 <= target <= 9:
            return 1
        return 0
    count = []
    for i in range(10):
        count.append(making_n(usable_numbers - 1, target - i))
    return sum(count)


if __name__ == '__main__':
    while True:
        try:
            n = int(input())
        except EOFError:
            break
        print(making_n(4, n))

Measured memory_bytes: 5592
#include <bits/stdc++.h>
#include <string>
using namespace std;
void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main() {
    init();
long long n,c=0,mi=INT_MAX;
cin>>n;
long long arr[n];
for(int i=0;i<n;i++){
    cin>>arr[i];
}
   for(int i=-100;i<=100;i++){
       for(int o=0;o<n;o++){
        c=pow(abs(i-arr[o]),2)+c;
       }
    mi=min(c,mi);
    c=0;
   }

cout<<mi;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import math

t=[int(input()) for _ in range(5)]
r=[(i-1)%10+1 for i in t]
c=r.index(min(r))
ans=0
for i in range(5):
    if i==c:
        ans+=t[i]
    else:
        ans+=math.ceil(t[i]/10)*10
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
	int N; cin >> N;
	cout << 0 << endl;
	fflush(stdout);
	string s; cin >> s;
	if(s[0] == 'V') return 0;
	int ok = 0;
	int ng = N-1;
	while(ok+2 != ng){
		int mid = (ok+ng)/2;
		if(mid & 1) mid += 1;
		cout << mid << endl;
		fflush(stdout);
		string t; cin >> t;
		if(t[0] == 'V') return 0;
		if(t == s) ok = mid;
		else ng = mid;
	}
	cout << ok+1 << endl;
	fflush(stdout);
	string m; cin >> m;
	if(m[0] == 'V') return 0;
	cout << ng << endl;
	fflush(stdout);
}

Measured memory_bytes: 852
import heapq
NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
each_days_list = [[] for _ in range(M)]
 
for i in range(N):
    ab = input()
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    if a <= M:
        each_days_list[a-1].append(b)

max_list = []
salary_count = 0
for i in range(M):
    for j in range(len(each_days_list[i])): 
        heapq.heappush(max_list,-each_days_list[i][j])
    if len(max_list) > 0:
        salary_count += -heapq.heappop(max_list)
        
print(salary_count)

Measured memory_bytes: 18472
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 105;

int n;
char s[N], t[N];

int main(){
    scanf("%d", &n);
    scanf("%s", s);
    scanf("%s", t);
    for(int ln = n;ln >= 0;ln--){
        int bad = 0;
        for(int i = 0;i < ln; i++){
            if(t[i] != s[n - ln + i]) bad = 1;
        }
        if(bad) continue;
        printf("%d\n", 2 * n - ln);
        return 0;
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, ans = 0;
	string s; cin >> n >> s;
	rep(i, n - 2) if(s.substr(i, 3) == "ABC") ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <exception>

#include <fstream>

#include <functional>

#include <iomanip>

#include <ios>

#include <iosfwd>

#include <iostream>

#include <istream>

#include <iterator>

#include <limits>

#include <list>

#include <locale>

#include <map>

#include <memory>

#include <new>

#include <numeric>

#include <ostream>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <stdexcept>

#include <streambuf>

#include <string>

#include <typeinfo>

#include <utility>

#include <valarray>

#include <vector>



#if __cplusplus >= 201103L

#include <array>

#include <atomic>

#include <chrono>

#include <condition_variable>

#include <forward_list>

#include <future>

#include <initializer_list>

#include <mutex>

#include <random>

#include <ratio>

#include <regex>

#include <scoped_allocator>

#include <system_error>

#include <thread>

#include <tuple>

#include <typeindex>

#include <type_traits>

#include <unordered_map>

#include <unordered_set>

#endif
using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 1;
	while (n >= ans) {
		ans *= 2;
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int h[n];
  rep(i,n)cin>>h[i];
  int ans = 0;
  rep(i,n){
    bool flag = 1;
    rep(j,i){
      if(h[j]>h[i])flag = 0;
    }
    if(flag)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int n,minv;
signed main(){
    cin>>n;
    minv=n;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
            minv=n/i;
        }
    }
    int ans=0;
    while(minv){
        minv/=10;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAXN = 1e5+1;
char s1[MAXN],s2[MAXN];

void solve() {
	string s;
	cin >> s;
	int n = (int)s.length();
	char c = 0;
	for (int i = 0; i < n; ++i) {
		s1[i] = (char)('0'+c);
		s2[i] = (char)('0'+(1-c));
		c = 1-c;
	}

	int n1 = 0, n2 = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] != s1[i]) {
			++n1;
		}
		if (s[i] != s2[i]) {
			++n2;
		}
	}

	cout << min(n1,n2) << '\n';
}

	/////////// End Solution ///////////////////////////////////////

	//////// Initialization ////////////////////////////////////

int main() {

		#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
		#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

		#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
		#endif

	return 0;
}

	//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 720
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<int> a(n);
    REP(i,n) cin>>a[i];
    int k=0;
    bool itiro = true;
    int ohajiki = 32;
    while(1){
      if(ohajiki==0) break;
      if(itiro){
        ohajiki -= (ohajiki-1)%5;
        cout<<ohajiki<<endl;
        itiro = false;
      }else{
        ohajiki = max(0,ohajiki-a[k]);
        k = (k+1)%n;
        cout<<ohajiki<<endl;
        itiro = true;
      }
    }
  }

  return 0;
}

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

typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<ll> la(n);
  for (ll &a: la) cin >> a;
  ll ans = 0;
  ll money = 0;
  for (ll a: la) {
    // cerr << a << " " << money << endl;
    if (a-1 <= money) {
      money = max(money, a);
      continue;
    }
    ans += (a-1)/(money+1);
    if (money == 0) money = 1;
  }
  cout << ans << endl;
}



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

#define endl '\n'
#define int long long

const int N = 1e5+9;
int cache[N], h[N], n, k;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> k;
	for(int i = 1; i <= n; i ++) {
		cin >> h[i];
	}
	for(int i = n-1; i > 0; i --) {
		cache[i] = 1e9;
		for(int j = 1; j <= k and i+j <= n; j ++) {
			cache[i] = min(cache[i], abs(h[i]-h[i+j])+cache[i+j]);
		}
	}
	cout << cache[1] << endl;

	return 0;
}

Measured memory_bytes: 5216
from itertools import permutations
N,M,R = map(int,input().split())
r = list(map(int,input().split()))
for i in range(R):
  r[i] -= 1
g = [[10 ** 8] * N for i in range(N)]
for i in range(M):
  A,B,C = map(int,input().split())
  A -= 1 
  B -= 1
  g[A][B] = C
  g[B][A] = C
def warchall_floyd(n):
  for i in range(n):
    #経由する頂点
    for j in range(n):
      #始点
      for k in range(n):
        #終点
        g[j][k] = min(g[j][k],g[j][i]+g[i][k])
        
warchall_floyd(N)
ans = float('inf')
for i in permutations(r):
  now = 0
  for j in range(R-1):
    now += g[i[j]][i[j+1]]
  if now < ans:
    ans = now
print(ans)


Measured memory_bytes: 74908
#include<iostream>
using namespace std;
const int MAX_N=1001000;
bool table[MAX_N];

int main(){
	int n,m;
		for(int i=0;i<MAX_N;i++)table[i]=false;
		
		table[1]=table[2]=table[3]=table[5]=true;
		for(int i=2;i<MAX_N;i++){
		
		if(table[i]){
		if(i*2<MAX_N)table[i*2]=true;
		if(i*3<MAX_N)table[i*3]=true;
		if(i*5<MAX_N)table[i*5]=true;
		}
	}
	
	while(cin>>n>>m,n&&m){
		int ans=0;
		for(int i=n;i<=m;i++){
			if(table[i]){
			ans++;
			}
		}
		cout<<ans<<endl;
	}
	

	

	
	return 0;
}

Measured memory_bytes: 2132
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            long X = sc.nextLong();
            long K = sc.nextLong();
            long D = sc.nextLong();

            X = Math.abs(X);

            if (K <= X / D) {
                System.out.println(Math.abs(X - D * K));
                return;
            }

            long l = 0;
            long r = K;
            for (; l + 1 < r;) {
                long c = (l + r) / 2;
                if (c <= X / D) {
                    l = c;
                } else {
                    r = c;
                }
            }

            if ((K - l) % 2 == 0) {
                System.out.println(Math.abs(X - l * D));
            } else {
                System.out.println(Math.abs(X - (l + 1) * D));
            }
        }
    }
}


Measured memory_bytes: 27112
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ull a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

int main(void) {
    string ss;
    cin >> ss;
    
    if (ss[0] == ss[1] && ss[1] == ss[2] && ss[0] == ss[2]) {
        cout << "No" << endl;

    } else {
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,d[51],i,j,sum=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){scanf("%d",&d[i]);}
	for(i=1;i<=n-1;i++){
		for(j=i+1;j<=n;j++){sum=sum+d[i]*d[j];}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256