akhauriyash/Code-Regression huggingface dataset:
s = input()
K = int(input())
s_list = []
for i in range(len(s)):
	for j in range(i + 1, i + K + 1):
		s_list.append(s[i:j])
s_set = set(s_list)
ans = list(s_set)
ans.sort()
print(ans[K - 1])

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 100000
vector<int> G[MAX];
int id[MAX],pa[MAX],dp[MAX],used[MAX];
void dfs(int v,int d){
  dp[v]=d;
  for(int i=0;i<(int)G[v].size();i++){
    dfs(G[v][i],d+1);
    pa[G[v][i]]=v;
  }
}
signed main(){
  int n;
  cin>>n;
  for(int i=0,k;i<n;i++){
    cin>>id[i]>>k;
    G[id[i]].resize(k);
    for(int j=0;j<k;j++){
      cin>>G[id[i]][j];
      used[G[id[i]][j]]=1;
    }
  }
  memset(pa,-1,sizeof(pa));
  for(int i=0;i<n;i++){
    if(!used[i]) dfs(i,0);
  }
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<pa[i]<<", depth = "<<dp[i];
    if(pa[i]<0) cout<<", root, [";
    else if(!G[i].size()) cout<<", leaf, [";
    else cout<<", internal node, [";
    for(int j=0;j<(int)G[i].size();j++){
      if(j) cout<<", ";
      cout<<G[i][j];
    }
    cout<<"]"<<endl;
  }
  return 0;
}



Measured memory_bytes: 9424
import sys
import os
import itertools


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    H = list(map(int, sys.stdin.readline().split()))

    ret = 'Yes'
    tmp = -1
    for n in range(N):
        if tmp > H[n]:
            if tmp != H[n] + 1:
                ret = 'No'
            else:
                tmp = H[n] + 1
        else:
            tmp = H[n]

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14476
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double n = sc.nextDouble();
        double x = sc.nextDouble();
        int t = sc.nextInt();
        System.out.println((int)(t * Math.ceil(n/x)));
        
    }
}



Measured memory_bytes: 37280
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef map<int,int> MPi; typedef pair<Int,Int> Pl; typedef int8_t shor;
const int mod = 1000000007;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

	int n,c=0; cin>>n; V(Pi) ans;
	if(n%2){
		for (int i = 1; i < n; i++){ans.push_back(Pi(i,n)); c++;}
	}
	for (int i = 1; i <= n/2; i++){
		for (int j = i+1; j <= n/2; j++){
			ans.push_back(Pi(i,j));
			ans.push_back(Pi(i,n+1-(n%2)-j));
			ans.push_back(Pi(n+1-(n%2)-i,j));
			ans.push_back(Pi(n+1-(n%2)-i,n+1-(n%2)-j));
			c+=4;
		}
	}
	cout<<c<<'\n';
	for(auto e:ans)cout<<e.first<<' '<<e.second<<'\n';
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve() {
	int ans = 0;

	bool V[MAX];
	for (int i = 0; i < n; i++) {
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B + n);
	for (int i = 0; i < n; i++)T[B[i]] = i;
	for (int i = 0; i < n; i++) {
		if (V[i])continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while (1) {
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if (V[cur])break;
		}
			ans += min(S + (an - 2)*m, m + S + (an + 1)*s);
	}

		return ans;
}

	int main() {
		cin >> n;
		s = VMAX;
		for (int i = 0; i < n; i++) {
			cin >> A[i];
			s = min(s, A[i]);
		}
		int ans = solve();
		cout << ans << endl;

		return 0;
	}

Measured memory_bytes: 3180
a=int(input())
b=int(input())
c=int(input())
x=int(input())

ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k  == x:
                ans+=1

print(ans)


Measured memory_bytes: 9056
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static int N;

  public static void main(String[] args) {
    N = sc.nextInt();
    int[] hist = new int[100001];
    for (int i = 0; i < N; i++) {
      hist[sc.nextInt()]++;
    }
    int ans = 0;
    int two = 0;
    for (int i = 0; i < hist.length; i++) {
      if (hist[i] >= 3) {
        int count = (hist[i] - 1) / 2;
        ans += count;
        hist[i] -= count * 2;
      }
      if (hist[i] == 2) ++two;
    }
    ans += (two + 1) / 2;
    System.out.println(N - ans * 2);
  }

}


Measured memory_bytes: 32204
#define isFile 0
#include <iostream>
#include <math.h>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <iomanip>
#include <map>
#include <set>
#include <utility>
#include <cstdlib>
#include <fstream>
#include <stdio.h>
#include <utility>
#include <ctype.h>
#include <cassert>
#include <list>
#include <numeric>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef long long int lli;
 
// #define mp make_pair 
#define pb push_back
#define pf push_front
#define ed cout << endl
#define PI acos(-1)
#define NAME "choose"
// #define name "choose"
#define all(x) x.begin(),x.end()
#define F first 
#define S second
#define T third
#define mk make_pair
#define sz(x) int(x.size())
#define repi(a, b) for (int i = a; i < b; i ++)
#define repj(a, b) for (int j = a; j < b; j ++)
#define yes cout << "yes"
#define no cout << "no"
 
const ll MOD = 1e7 + 9;
const long double EPS = 3e-16;
const ll MAXN = 2e5 + 7;
const ll INF = 1e9;
 
void file(){
    freopen(NAME".in", "r", stdin);
    if (isFile) freopen(NAME".out", "w", stdout);
}


void solve(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(true){
    c-=b;
    if (c <= 0){
      cout << "Yes";ed;
      return;
    }
    a-=d;
    if (a <= 0){
      cout << "No";
      return;
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  // file();
  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  return 0;
}
    


Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
	int n,m,h,l,i,t[2],x;
	for(scanf("%d",&n);n--;)
	{
		scanf("%d",&m);
		for(h=0,l=10000,i=0;i<m;i++)
		{
			scanf("%d",&t[i%2]);
			if(i!=0)
			{
				x=t[i%2]-t[(i+1)%2];
				if(x>=0)
					h=h>x?h:x;
				else
					l=l<x?l:x;
			}
		}
		printf("%d %d\n",h,l==10000?0:-l);
	}
	return 0;
}

Measured memory_bytes: 596
L = [1]
for b in range(2,32):
  for p in range(2,10):
    n = int(b**p)
    if n not in L and n <= 1000:
      L.append(n)
L = sorted(L)
X = int(input())
s = sum(x<=X for x in L)
print(L[s-1])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

void Main() {
  //自動整形防止用コメント
  int n;
  std::cin >> n;
  std::cout << "ABC" << n << '\n';

  return;
}

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


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

bool bad(int a, int c, string s) {
    int cnt = 0;
    for(int i = a; i < c; ++i) {
        if(s[i] == '#') cnt++;
        else cnt = 0;
        if(cnt == 2) return true;
    }
    return false;
}

bool criss(int a, int c, string s) {
    int cnt = 0;
    a -= 2;
    c++;
    for(int i = a; i < c; ++i) {
        if(s[i] == '.') cnt++;
        else cnt = 0;
        if(cnt == 3) return false;
    }
    return true;
}

bool solve(int n, string s, int a, int b, int c, int d) {
    if(bad(a, c, s) || bad(b, d, s)) return false;

    if(d > c && b < a) {
        if(criss(a, c, s)) return false;
    }
    if(c > d && a < b) {
        if(criss(b, d, s)) return false;
    }

    return true;
}

int32_t main() {

    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    string s; cin >> s;

    bool ans = solve(n, s, a, b, c, d);

    if(ans) cout << "Yes\n";
    else cout << "No\n";
    
    return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  std::size_t N, K;
  std::cin >> N >> K;
  std::vector<bool> Nth_sunuke(N, false);

  for(std::size_t i=0; i<K; ++i)
  {
    std::size_t di;
    std::cin >> di;
    for(std::size_t d=0; d<di; ++d)
    {
      std::size_t sunuke;
      std::cin >> sunuke;
      Nth_sunuke.at(sunuke - 1) = true;
    }
  }

  std::cout << std::count_if(Nth_sunuke.begin(), Nth_sunuke.end(), [](const bool b) {return not b;}) << std::endl;
  return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  ans += min(k, a);
  k -= min(k, a);
  k -= min(k, b);
  ans -= min(k, c);

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


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long count = 0,N;
    string S;
  cin >> N;
  vector<long long> c(5,0);
  froop1(0,N){
    cin >> S;
   if(S[0] == 'M')c.at(0)++;
     else if(S[0] == 'A')c.at(1)++;
    else if(S[0] == 'R')c.at(2)++;
    else if(S[0] == 'C')c.at(3)++;
    else if(S[0] == 'H')c.at(4)++;
  }
  for(int i = 0;i < 5;i++){
    for(int j = i;j < 5;j++){
		for(int k = j;k < 5;k++){
         if(i != j && j != k && k != i){
           count += c.at(i) * c.at(j) * c.at(k);
        }
        }
    }
  }
  cout << count << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n;
  string s;
  cin >> n >> s;
  ll pointer=0,need=0;
  rep(i,n){
    if(s[i]=='(')pointer++;
    else{
      if(pointer==0)need++;
      else pointer--;
    }
  }
  string t="";
  rep(i,need)t+='(';
  s=t+s;
  rep(i,pointer)s+=')';
  cout << s << endl;
          
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      	int a=0,w=0,t=0,r=0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
      	for(int i=0;i<N;i++){
          String s = sc.next();
          if(s.equals("AC")){
            a++;
          }
          if(s.equals("WA")){
            w++;
          }
          if(s.equals("TLE")){
            t++;
          }
          if(s.equals("RE")){
            r++;
          }
        }
      	System.out.println("AC x "+a);
      	System.out.println("WA x "+w);
      	System.out.println("TLE x "+t);
      	System.out.println("RE x "+r);
	}
}

Measured memory_bytes: 58848
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int k, d;
	cin >> k >> d;
	if (k * 500 >= d) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}









Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;

LL n,m,col[200005] = {0};
vector <LL> G[200005];
LL flg,siz,cnt[3] = {0};
LL ans;

void dfs(LL u,LL f){
	for(LL i = 0;i < G[u].size();i ++){
		LL v = G[u][i];
		if(col[v] && col[v] == col[u]) flg = 1;
		if(!col[v]){
			col[v] = 3 - col[u]; siz ++;
			dfs(v,u);
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v;
	cin >> n >> m;
	
	for(LL i = 1;i <= m;i ++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	for(LL i = 1;i <= n;i ++){
		if(col[i]) continue;
		flg = 0; siz = 1; col[i] = 1; dfs(i,0);
//		cout << i << ' ' << siz << endl;
		if(siz == 1) cnt[2] ++;
		else cnt[flg] ++;
	}
//	cout << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << endl;
	ans = (2 * n * cnt[2] - cnt[2] * cnt[2]) + (2 * cnt[0] * cnt[0]) + (cnt[1] * cnt[1] + cnt[1] * cnt[0] * 2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15360
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n;
    scan(n);
    string s, t;
    scan(s, t);
    writeln(zip(s, t).map!(a => a[0].to!string ~ a[1].to!string).joiner);
}

















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static long MOD = 1000000007L;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		long N = Long.parseLong(in.readLine());

		int sqrt = (int) Math.floor(Math.sqrt((double) N));
		long result = (long) sqrt * (long) sqrt;
		System.out.println(result);

	}
}


Measured memory_bytes: 21332
#include <stdio.h>

static const int N = 1000;

int main(){
  int i, j, A[N], length, swap, count = 0;

  scanf("%d",&length);
  for(i = 0; i < length; i++){
    scanf("%d",&A[i]);
  }
  
  for(i = 0; i < length-1; i++){
    for(j = length-1; j >= i+1; j--){
      if(A[j] < A[j-1]){
	swap = A[j];
	A[j] = A[j-1];
	A[j-1] = swap;
	count++;
      }
    }
  }

  for(i = 0; i < length; i++){
    printf("%d",A[i]);
    if(i <= length-2) printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 608
n, m = map(int, input().split())
INF = pow(10, 15)

alist, blist, clist = [], [], []
for _ in range(m):
  a, b, c = map(int, input().split())
  alist.append(a-1)
  blist.append(b-1)
  clist.append(-c)
dist = [INF for _ in range(n)]
dist[0] = 0
for _ in range(n-1):
  for a, b, c in zip(alist, blist, clist):
    if dist[a] == INF:  # まだ未到達なので更新しない
      continue
    if dist[b] > dist[a] + c:  # もし判明している到達コストよりも小さいなら
      dist[b] = dist[a] + c

ans = dist[n-1]

negative = [False for _ in range(n)]

for _ in range(n):
  for a, b, c in zip(alist, blist, clist):
    if dist[a] == INF:
      continue
    if dist[b] > dist[a] + c:
      dist[b] = dist[a] + c
      negative[b] = True
    if negative[a]:
      negative[b] = True

if negative[n-1]:
  print("inf")
else:
  print(-ans)


Measured memory_bytes: 3316
x, y, z= gets.split(" ")

l = [x.to_i, y.to_i, z.to_i]
max = l.max

d = x.to_i * y.to_i * z.to_i / max
d = 0 if x.to_i.modulo(2)==0 || y.to_i.modulo(2)==0 || z.to_i.modulo(2)==0

p d

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

int a[10000];
int buf[100];
int main(void){
  int H,W,N;
  int a_index=0;
  cin >> H >> W >> N;
  for(int i=0;i<N;i++) cin >> a[i];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      buf[j]=a_index+1;
      a[a_index]--;
      if(a[a_index]==0) a_index++;
    }
    if(i%2==0){
      cout << buf[0];
      for(int j=1;j<W;j++) cout << " " << buf[j];
    }else{
      cout << buf[W-1];
      for(int j=W-2;j>=0;j--) cout << " " << buf[j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include<stdio.h>

 int main(){
   int x,y,i;

   while(1){
     
     scanf("%d %d",&x,&y);
     
     if(x==0 && y==0){
       break;
       
     }else{
       i++;
       if(x>y){
	 printf("%d %d\n",y,x);
       }else{
	 printf("%d %d\n",x,y);
       }
     }
   }

     return 0;

}
   

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

int N, A[1 << 18];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];

	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		if (i == A[A[i]]) cnt++;
	}
	cout << cnt / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include <stdlib.h>
main(){
  int n,i,j,flg;
  char *a;
  long in;

  scanf("%d",&n);
  
  a = (char*)malloc((sizeof(char)*1000000000+1));//*n)+1);
  
  for(i=0;i<n;i++){
    a[i] = 0;
  }

  flg = 0;
  for(i=0;i<n;i++){
    scanf("%ld",&in);
    if(a[in] == 0){
      a[in] = 1;
    }else{
      flg = 1;
      break;
    }
  }

  if(flg == 0){
    printf("YES");
  }else{
    printf("NO");
  }
}

Measured memory_bytes: 976000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    ll ans = 1;
    bool ng = false;
    rep(i, n)
    {
        ll a;
        cin >> a;
        if (a == 0){
            cout << 0 << endl;
            return 0;
        }
        if (ng || a > 1000000000000000000 / ans)
            ng = true;
        else
            ans *= a;
    }
    if (ng)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int a, b; cin >> a >> b;
	for(Int i=1; i<=10000; ++i){
		Int x = i * 108 / 100 - i;
		Int y = i * 110 / 100 - i;
		if(x == a && y == b){
			cout << i << "\n";
			return 0;
		}
	}
	cout << -1 << "\n";
}

Measured memory_bytes: 256
// DP

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; ++i)

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 A[100010][3];

int main() {
  int n; cin >> n;
  rep(i,n){ rep(j,3) cin >> A[i][j]; }
  
  vector<vector<ll>> dp(100010, vector<ll>(3,0));

  rep(i,n) {
    rep(j,3) {
      rep(k,3) {
        if(j == k) continue;
        chmax( dp[i+1][k], dp[i][j] + A[i][k] );
      }
    }
  }
  ll ans = 0;
  rep(j,3) chmax(ans, dp[n][j]);
  cout << ans << endl;
}

Measured memory_bytes: 11156
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <stack>
#include <cmath>
#include <queue>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MaxN = 3e5 + 5;

priority_queue <LL, vector<LL> , greater<LL> > pre_que;
priority_queue <LL> pos_que;
int a[MaxN];
int n;
LL pre_sum[MaxN], pos_sum[MaxN];

void solve1() {
	LL sum = 0;
	for(int i = 1; i <= 3 * n; i++) {
		pre_que.push(a[i]);
		sum += a[i];
		pre_sum[i] = sum;
		if(pre_que.size() > n) {
			sum -= pre_que.top();
			pre_que.pop();
			pre_sum[i] = sum;
		}
	}
}

void solve2() {
	LL sum = 0;
	for(int i = 3 * n; i >= 1; i--) {
		pos_que.push(a[i]);
		sum += a[i];
		pos_sum[i] = sum;
		if(pos_que.size() > n) {
			sum -= pos_que.top();
			pos_que.pop();
			pos_sum[i] = sum;
		}
	}
}
int main() 
{
	scanf("%d", &n);
	for(int i = 1; i <= 3 * n; i++) scanf("%d", &a[i]);
	solve1();
	solve2();
	LL ans = -1e18;
	for(int i = n; i <= 2 * n; i++)
		ans = max(ans, pre_sum[i] - pos_sum[i + 1]);
	printf("%lld\n", ans);
	return 0;
}


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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
//#define int long long
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  int n;cin >> n;
  int ans=0,min=200001;
  rep(i,n){
    int p;cin >> p;
    if(p<min)ans++;
    chmin(min,p);
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX(x, y) ((x) >= (y) ? (x) : (y))
int get_int() {
    int n = 0;
    int sign = 1;
    int c = getchar_unlocked();
    if(c == 45) sign = -1, c = getchar_unlocked();
    else if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n * sign;
}

typedef struct Node {
    int parent, left, right, depth, height, sibling;
} Node;
typedef struct BinaryTree {
    Node nodes[25];
    int root;
} BinaryTree;
void bt_init(BinaryTree *BT) {
    for(int i = 0; i < 25; ++i) BT->nodes[i].parent = -1;
}
void bt__depth(BinaryTree *BT, int id, int depth) {
    if(id == -1) return;
    Node *node = &BT->nodes[id];
    node->depth = depth;
    bt__depth(BT, node->left, depth + 1);
    bt__depth(BT, node->right, depth + 1);
}
int bt__height(BinaryTree *BT, int id) {
    int h1 = 0, h2 = 0;
    Node *node = &BT->nodes[id];
    if(~node->left) h1 = bt__height(BT, node->left) + 1;
    if(~node->right) h2 = bt__height(BT, node->right) + 1;
    return node->height = MAX(h1, h2);
}
int bt__sibling(BinaryTree *BT) {
    for(int i = 0; i < 25; ++i) {
        Node *node = &BT->nodes[i];
        if(node->parent == -1) {
            node->sibling = -1;
            continue;
        }
        int left = BT->nodes[node->parent].left;
        int right = BT->nodes[node->parent].right;
        if(left != i && ~left) node->sibling = left;
        else if(right != i && ~right) node->sibling = right;
        else node->sibling = -1;
    }
}
void bt_make(BinaryTree *BT) {
    for(int i = 0; i < 25; ++i) {
        if(BT->nodes[i].parent == -1) {
            BT->root = i;
            break;
        }
    }
    bt__depth(BT, BT->root, 0);
    bt__height(BT, BT->root);
    bt__sibling(BT);
}
void bt_add_node(BinaryTree *BT, int id, int left, int right) {
    BT->nodes[id].left = left;
    BT->nodes[id].right = right;
    if(~left) BT->nodes[left].parent = id;
    if(~right) BT->nodes[right].parent = id;
}
int main(int argc, char **argv) {
    int n = get_int();
    BinaryTree BT;
    bt_init(&BT);
    for(int i = 0; i < n; ++i) {
        int id = get_int();
        int left = get_int();
        int right = get_int();
        bt_add_node(&BT, id, left, right);
    }
    bt_make(&BT);

    for(int i = 0; i < n; ++i) {
        int degree = 0;
        ~BT.nodes[i].left && degree++;
        ~BT.nodes[i].right && degree++;
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d",
               i, BT.nodes[i].parent, BT.nodes[i].sibling, degree, BT.nodes[i].depth, BT.nodes[i].height);
        if(BT.nodes[i].parent == -1) puts(", root");
        else if(BT.nodes[i].left == -1 && BT.nodes[i].right == -1) puts(", leaf");
        else puts(", internal node");
    }
    return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    int ma = 0;
    bool plu = false;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        if(a[i] > ma) {
            plu = false;
            ma = a[i];
        } else if(a[i] == ma) plu = true;
    }
    int msa = 0;
    rep(i,n) {
        if(a[i] == ma) continue;
        chmax(msa,a[i]);
    }
    rep(i,n) {
        if(a[i] == ma) cout << (plu ? ma : msa) << endl;
        else cout << ma << endl;
    }
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void solve(VLL &p, VLL &m) {
  FOR(i, 1, p.size()) {
    cout << m.back() << " " << p[i] << endl;
    m.back() -= p[i];
  }

  rep(i, m.size()) {
    cout << p[0] << " " << m[i] << endl;
    p[0] -= m[i];
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VLL a(n);
  rep(i, n) cin >> a[i];
  VLL m, p;
  ll sum = 0;

  if(n == 2) {
    sort(all(a));
    cout << a[1] - a[0] << endl;
    cout << a[1] << " " << a[0] << endl;
    return 0;
  }

  rep(i, n) {
    if(a[i] >= 0)
      p.push_back(a[i]);
    else
      m.push_back(a[i]);

    sum += abs(a[i]);
  }

  if(p.size() > 0 && m.size() > 0) {
    cout << sum << endl;
    solve(p, m);
    return 0;
  }

  if(p.size() > 0) {
    sort(all(p));
    cout << sum - 2 * p[0] << endl;
    m.push_back(p[0] - p[1]);
    cout << p[0] << " " << p[1] << endl;
    VLL pp;
    FOR(i, 2, p.size()) pp.push_back(p[i]);
    solve(pp, m);
  } else {
    sort(all(m));
    cout << sum + 2 * m.back() << endl;
    ll mSize = m.size();
    p.push_back(m[mSize - 1] - m[mSize - 2]);
    cout << m[mSize - 1] << " " << m[mSize - 2] << endl;
    VLL mm;
    rep(i, mSize - 2) mm.push_back(m[i]);
    solve(p, mm);
  }

  return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<bool> nb(n+10,true);
  
  
  REP(i,m){
    int a;
    cin >> a;
    nb[a] = false; 
  }
  
  ll dp[n+10];
  REP(i,n+10){
    dp[i] = 0;
  }
  
  //cout << n << endl;
  dp[0] = 1;
  dp[1] = 1;
  ll mod = 1000000007;
  
  REP(i,n){
    if(nb[i]){
      if(nb[i+1]){
        dp[i+2] += dp[i] + dp[i+1];
        dp[i+2] %= mod; 
      }
      else{
        dp[i+2] += dp[i];
        dp[i+2] %= mod;   
      }
    }
    else{
      if(nb[i+1]){
        dp[i+2] += dp[i+1];
        dp[i+2] %= mod; 
      }
      else{
        cout << 0 << endl;
        return 0;  
      }
    }    
  }

  
  cout << dp[n] << endl;


}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"

// int mod=1e9+7;
// int min(int a,int b){
//     return (a<b)?a:b;
// }
// int max(int a,int b){
//     return (a>b)?a:b;
// }
// int fp(int a,int b){
//     if(b==0) return 1;
//     int x=fp(a,b/2);
//     x=(x*x)%mod;
//     if(b&1) x=(x*a)%mod;
//     return x;
// }


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 srand(time(0));
 int n,k;
 cin>>n>>k;
 long double a[n+1],b[n+1];
 for(int i=1;i<=n;i++)
 {
    cin>>a[i];
    b[i]=log(a[i]);
 }
 long double c[n+1];
 c[0]=0;
 for(int i=1;i<=n;i++)
 {
    c[i]=c[i-1]+b[i];
 }
 
 for(int i=k+1;i<=n;i++)
 {
    long double x=c[i]-c[i-k];
    long double y=c[i-1]-c[i-k-1];
    long double dif=x-y,e=(1.0/1e11);
   // cout<<fixed<<setprecision(8)<<x<<" "<<y<<" "<<x-y<<endl;
    if(dif>(e))
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
 }



}

Measured memory_bytes: 13200
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		int[][] x = new int[n][d];
		for(int i = 0;i < n; i++) {
			for(int j = 0; j <d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<array>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int n, k=1;
 cin >> n;
 double a[n], b[n], s=0, ans;
 for(int i=1;i<n+1;i++) k*=i;
 for(int i=0;i<n;i++) cin >> a[i] >> b[i];
// for(int i=0;i<n;i++) cout << a[i] << b[i] << endl;
 vector<int> v(n);
 iota(v.begin(), v.end(), 0);
 do{
 	for(int i=1;i<n;i++){
      s+=sqrt((a[v[i]]-a[v[i-1]])*(a[v[i]]-a[v[i-1]])+(b[v[i]]-b[v[i-1]])*(b[v[i]]-b[v[i-1]]));
//      cout << v[0] << " "<<v[1]<< " " <<v[2]<<" " <<sqrt((a[i]-a[i-1])*(a[i]-a[i-1])+(b[i]-b[i-1])*(b[i]-b[i-1])) << endl;
    }
 }while(next_permutation(v.begin(),v.end()));
 cout << std::fixed;
 std::cout << std::setprecision(8) << s/k;
 return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

		while(true){
			int h=sc.nextInt(), w=sc.nextInt();
			if(h==0 && w==0) break;
			int[][] map = new int[h][w];

			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					map[i][j] = sc.nextInt();
				}
			}

			int si=sc.nextInt(), sj=sc.nextInt();
			int gi=sc.nextInt(), gj=sc.nextInt();

			Queue<State> open = new PriorityQueue<State>();
			Set<State> closed = new HashSet<State>();

			State st = null;
			open.add(new State(0,new Dice(si,sj,1,6,4,3,5,2)));
			State ans = null;

			while(!open.isEmpty()){
				st = open.poll();
				if(closed.contains(st)) continue;
				closed.add(st);
				if(st.d.i == gi && st.d.j == gj){
					ans = st;
					break;
				}
				open.addAll(st.nexts(map));
			}
			System.out.println(ans.cost);
		}
	}
}

class State implements Comparable<State>{
	int cost;
	Dice d;

	State(int cost,Dice d){
		this.cost = cost;
		this.d = d.copy();
	}

	List<State> nexts(int[][] map){
		List<State> sts = new ArrayList<State>();

		for(int i=0;i<4;i++){
			Dice dice = d.copy();
			if(dice.move(map,i)){
				sts.add(new State(cost+dice.b*map[dice.i][dice.j], dice));
			}
		}

		return sts;
	}

	public int compareTo(State st){
		return cost - st.cost;
	}

	public boolean equals(Object o){
		State st = (State)o;
		return this.d.equals(st.d);
	}

	public int hashCode(){
		return d.i + d.j + d.t + d.b + d.w + d.e + d.n + d.s;
	}
}

class Dice{
	int i,j;
	int t,b,w,e,n,s;

	Dice(int i,int j,int t,int b,int w,int e,int n,int s){
		this.i = i;
		this.j = j;
		this.t = t;
		this.b = b;
		this.w = w;
		this.e = e;
		this.n = n;
		this.s = s;
	}

	public boolean equals(Object dtmp){
		Dice d = (Dice)dtmp;
		return this.i == d.i && this.j == d.j &&
			this.t == d.t && this.b == d.b && this.w == d.w &&
			this.e == d.e && this.n == d.n && this.s == d.s;
	}

	boolean move(int[][] map,int d){
		Dice tmp = this.copy();

		switch(d){
		case 0:
			if(i-1<0) return false;
			i = i-1;
			t = tmp.s; b = tmp.n; n = tmp.t; s = tmp.b;
			break;
		case 1:
			if(j+1>=map[0].length) return false;
			j = j+1;
			t = tmp.w; b = tmp.e; w = tmp.b; e = tmp.t;
			break;
		case 2:
			if(i+1>=map.length) return false;
			i = i+1;
			t = tmp.n; b = tmp.s; n = tmp.b; s = tmp.t;
			break;
		case 3:
			if(j-1<0) return false;	
			j = j-1;
			t = tmp.e; b = tmp.w; w = tmp.t; e = tmp.b;
			break;
		}
		return true;
	}

	Dice copy(){
		return new Dice(i,j,t,b,w,e,n,s);
	}
}

Measured memory_bytes: 15000
import numpy as np

def distance(a, b):
    dis = 0
    for d in range(D):
        dis += (a[d] - b[d])**2
    return np.sqrt(dis)

N,  D =  list(map(int, input().strip().split()))
points = []
for n in range(N):
    points.append(list(map(int, input().strip().split())))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if(i == j):
            continue
        dis = distance(points[i], points[j])
        ans += (dis % 1) == 0.0
print(ans)

Measured memory_bytes: 21092
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

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

  int ans = 0;
  for (int i = 0; i < N; i++){
    int X; cin >> X;
    ans += 2 * min(X, K - X);
  }
  cout << ans << endl;
   
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char s[100000];

int main(){

    scanf("%s", &s);
    int len = strlen(s),i,hugs=0,ans;
    for(i=0;i<len;i++ ){
       if (s[i]!=s[len-i-1])

        hugs=hugs+1;
    }
    ans=hugs/2;
    printf("%d\n",ans);
    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
int main() {
    int n,ans = 0;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        ans += s[i];
    }
    sort(s.begin(),s.end());
    if(ans %10 != 0){
        cout << ans << endl;
        return 0;
    }else{
        for (int i = 0; i < n; ++i) {
            if(s[i] %10 != 0){
                ans -= s[i];
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

vector<ll> ANS;
int a[20];
int b[20];

bool check(int p, int sum) {
	for (int i = 0; i < p; i++) {
		int x = min(9, sum);
		b[i] = x;
		sum -= x;
	}
	ll x = 0, y = 0, sx = 0, sy = 0;
	for (int i = 17; i >= 0; i--) {
		x = 10 * x + a[i];
		y = 10 * y + b[i];
		sx += a[i];
		sy += b[i];
	}
	if (y <= x) throw;
//	if (x * sy > y * sx)
//		cerr << x << " " << y << "   " << x * sy << " " << y * sx << endl;
	return x * sy <= y * sx;
}

void check() {
	for (int p = 0; p < 16; p++) {
		for (int i = p + 1; i < 16; i++)
			b[i] = a[i];
		for (int x = a[p] + 1; x < 10; x++) {
			b[p] = x;
			for (int sum = 0; sum <= 9 * p; sum++) {
				if (!check(p, sum))
					return;
			}
		}
	}
	ll x = 0;
	for (int i = 17; i >= 0; i--)
		x = 10 * x + a[i];
	ANS.push_back(x);
}

void brute(int pos, int L) {
	if (pos == -1) {
		check();
		return;
	}
	if (L - pos <= 3 || (L - pos == 4 && a[L - 1] == 1)) {
		for (int x = 0; x < 10; x++) {
			if (pos == L - 1 && x == 0) continue;
			a[pos] = x;
			brute(pos - 1, L);
		}
	} else {
		a[pos] = 9;
		brute(pos - 1, L);
	}
}

void genWithLen(int L) {
	brute(L - 1, L);
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	for (int l = 1; l <= 15; l++)
		genWithLen(l);
	sort(ANS.begin(), ANS.end());
//	cout << (int)ANS.size() << endl;
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
		cout << ANS[i] << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n+2];
		int s[] = new int[n+2];
		a[0]=0;
		for(int i=1; i<=n; i++) a[i]=sc.nextInt();
		a[n+1]=0;

		s[0]=0;
		for(int i=1; i<=n+1; i++) {
			s[i]=s[i-1]+ Math.abs(a[i]-a[i-1]);
		}

		for(int i=1; i<n+1; i++) {
			long ans = 0;
			if((a[i] <a[i-1] && a[i] < a[i+1]) || (a[i] > a[i-1] && a[i] > a[i+1])){
				ans = s[i-1] + Math.abs(a[i+1]-a[i-1]) + s[n+1] - s[i+1];
			} else {
				ans = s[n+1];
			}
			System.out.println(ans);
		}
		sc.close();
	}
}


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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3912
fun main(args: Array<String>) = yorukatsu21b()

fun yorukatsu21b() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val answer = aList.map {
        var curr = it
        var count = 0
        while (curr % 2 == 0L && curr > 0) {
            curr /= 2
            count++
        }
        count.toLong()
    }.sum()

    println(answer)
}


Measured memory_bytes: 40156
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
//#define BIG 10e18
#define ll long long
int  a,b,c;
long long k;
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    scanf("%lld",&k);


    if(k%2==0)
        k=a-b;
    else
    {
        k=b-a;

    }
    printf("%lld",k);
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <utility>
#include <vector>
#include <cstdio>
using namespace std;

int n, a1, b1, c1, a2, b2, c2;
vector <pair <int, int> > A, B;
long long dp1[5005], dp2[25000005];
int main() {
  scanf("%d\n", &n);
  scanf("%d %d %d", &a1, &b1, &c1);
  scanf("%d %d %d", &a2, &b2, &c2);
  if (a1 != a2)
    if (a1 < a2) A.push_back({a1, a2});
    else B.push_back({a2, a1});
  if (b1 != b2)
    if (b1 < b2) A.push_back({b1, b2});
    else B.push_back({b2, b1});
  if (c1 != c2)
    if (c1 < c2) A.push_back({c1, c2});
    else B.push_back({c2, c1});
  for (auto &p : A)
    for (int j = 0; j + p.first <= n; ++ j)
      dp1[j + p.first] = max(dp1[j + p.first], dp1[j] + p.second);
  long long now = 0, ans = 0;
  for (int i = 0; i <= n; ++ i)
    now = max(now, dp1[i] + n - i);
  for (auto &p : B)
    for (int j = 0; j + p.first <= now; ++ j)
      dp2[j + p.first] = max(dp2[j + p.first], dp2[j] + p.second);
  for (int i = 0; i <= now; ++ i)
    ans = max(ans, dp2[i] + now - i);
  printf("%lld\n", ans);
}

Measured memory_bytes: 195584
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
#include <stdbool.h>


//using ll = long long;
int ASC( void *a,  void *b) {
	return strcmp(*(const char **)a, *(const char **)b);//降順
}
int GCD(int a, int b) {	//最大公約数
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int min(double a, double b ) {
	if (a < b) {
		return a;
	}
	else
		return b;
}
int max(int a, int b) {
	if (a < b)
		return b;
	else
		return a;
}
int main(void)
{
	int a;
	scanf("%d",&a);
	printf("%d",a+a*a+a*a*a);
	return 0;
}//pd pdp

Measured memory_bytes: 1732
#include<iostream>
#include<list>
using namespace std;
int main()
{
    list<long long> l;
    list<long long>::iterator it = l.end();
    long long n, i,b,x; int a;
    cin >> n;
    for (i = 0; i < n; i++){
        cin >> a;
        if (a == 0) {
            cin >> x;
            l.insert(it, x);
            it--;
        }
        else if (a == 1) {
            cin >> x;
            advance(it, x);
        }
        else if (a == 2) it = l.erase(it);
    }
    for (it = l.begin(); it != l.end(); it++) cout << *it << endl;
}


Measured memory_bytes: 18644
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
#define MAX 20
#define INF 1e9
 
vector<int> vec,v[MAX],a[MAX];
 
void init(int N){
    vec.clear();
    for(int i = 0 ; i < MAX ; i++){
	v[i].clear();
    }
    for(int i = 1 ; i < 1<<N ; i++){
	int idx = __builtin_popcount(i);
	v[idx-1].push_back(i);
    }
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < (int)v[i].size() ; j++){
	    vec.push_back(v[i][j]);
	}
    }
}
 
int main(){
    int N,U,c[MAX],k,r;
    bool used[MAX] = {false};
 
    while(cin >> N >> U, (N | U)){
	if(!used[N-1]){
	    init(N);
	    a[N-1] = vec;
	    used[N-1] = true;
	}else{
	    vec = a[N-1];
	}
	int arr[MAX];
	for(int i = 0 ; i < N ; i++){
	    cin >> c[i] >> k;
	    int S = 0;
	    for(int j = 0 ; j < k ; j++){
		cin >> r;
		S |= 1<<r;
	    }
	    arr[i] = S;
	}
	int ans = INF;
	for(int i = 0 ; i < (int)vec.size() ; i++){
	    int S = vec[i];
	    int cnt = 0, total = 0;
	    bool flg = true;
	    for(int j = 0 ; j < N ; j++){
		if(S >> j & 1){
		    if((S & arr[j]) == arr[j]){
			cnt += c[j]; total++;
		    }else{
			flg = false;
			break;
		    }
		}
	    }
	    if(flg && cnt >= U){
		ans = total;
		break;
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

template <class T>inline T updmax(T &a, T b) { return a = max(a, b); }
template <class T>inline T updmin(T &a, T b) { return a = min(a, b); }

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod-this->v); }
	modint &operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod)v -= mod;
		return *this;
	}
	modint &operator-=(const modint rhs) {
		if (v < rhs.v)v += mod;
		v -= rhs.v;
		return *this;
	}
	modint &operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) {
				ret *= a;
			}
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint &operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
};

template<class T>
T fastpow(T a, long long p){
	T tmp = a;
	T ret = 1;
	while(p){
		if(p & 1)ret *= tmp;
		p >>= 1;
		tmp = tmp * tmp;
	}
	return ret;
}

const int MOD = 998244353;
using mint = modint<MOD>;

char s[200005];
mint dp[200005][3][3];

void dfs(set<string> &ss, string c){
	ss.insert(c);
	for(int i=0; i < c.length()-1; i++){
		if(c[i] == c[i+1])continue;
		for(int j=0; j < 3; j++){
			char ch = 'a' + j;
			if(c[i] != ch && c[i+1] != ch){
				char ch0 = ch, ch1 = ch;
				swap(c[i], ch0);
				swap(c[i+1], ch1);
				if(ss.end() == ss.find(c))dfs(ss, c);
				swap(c[i], ch0);
				swap(c[i+1], ch1);
			}
		}
	}
}

int main()
{
	scanf("%s", &s);
	int n = strlen(s);
	bool allsame = true, same = false;
	for(int i=0; i < n-1; i++){
		if(s[i] == s[i+1])same = true;
		else allsame = false;
	}
	if(allsame)printf("1\n");
	else if(n <= 4){
		set<string> ss;
		dfs(ss, string(s));
		printf("%d\n", ss.size());
	}else{
		dp[0][0][0] = dp[0][1][1] = dp[0][2][2] = 1;
		for(int i=0; i < n-1; i++){
			for(int j=0; j < 3; j++){
				for(int k=0; k < 3; k++){
					for(int l=0; l < 3; l++){
						if(l != k)dp[i+1][(j+l)%3][l] += dp[i][j][k];
					}
				}
			}
		}
		int sum = 0;
		for(int i=0; i < n; i++)sum += s[i] - 'a';
		sum %= 3;
		mint ret = fastpow(mint{3}, n-1) - dp[n-1][sum][0] - dp[n-1][sum][1] - dp[n-1][sum][2] + (1 - same);
		printf("%lld\n", ret.v);
	}
	return 0;
}

Measured memory_bytes: 14464
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#define ll long long
#define pr(a) cerr<<#a<<"="<<a<<endl
#define pri(a,lo) {cerr<<#a<<"={";for (int ol=0;ol<=lo;ol++)cerr<<a[ol]<<",";cout<<"}"<<endl;}
using namespace std;
#define N 1010000
int n,i,o,ans,a[N];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++) 
	{
		scanf("%d",&o);
		if (o>n) ans++;
		else a[o]++;
	}
	for (i=1;i<=n;i++) 
	{
		if(a[i]>=i) ans+=a[i]-i;
		else ans+=a[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256