akhauriyash/Code-Regression huggingface dataset:
package main

import (
  "fmt"
)

func main() {
  var n int 
  fmt.Scan(&n)
  res := make(map[int]bool)
  for i := 0; i < n; i++ {
    var a int 
    fmt.Scan(&a)
    res[a] = true
  }
  fmt.Println(len(res))
}

Measured memory_bytes: 512
n = int(raw_input())
a = map(int,raw_input().split())
b = []
for i in range(n):
  b.append(a[i]-i-1)
b.sort()
if len(b)%2 == 0:
  c = b[len(b)/2]
else:
  c = b[(len(b)-1)/2]
d = 0
for i in range(n):
  d += abs(b[i]-c)
print d

Measured memory_bytes: 22232
#include <iostream>
#include <vector>

using namespace std;

long long pow_mod(long long a, long long b, long long mod) {
    long long r = 1;
    for (long long i = 1, j = a; i <= b; i <<= 1, j = (j * j) % mod) {
        if ((i & b) > 0) {
            r = (r * j) % mod;
        }
    }
    return r;
}

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

    long long mod = 1000000007;
    long long res = 0;

    vector<long long> c(k + 1);
    for (int i = k; i >= 1; i--) {
        c[i] = pow_mod(k / i, n, mod);
        for (int j = 2 * i; j <= k; j += i) {
            c[i] = (c[i] - c[j] + mod) % mod;
        }
        res = (res + i * c[i]) % mod;
    }

    cout << res << endl;
}


Measured memory_bytes: 4036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
char s[300];
int n,i;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for (i=1;i<=n;i++)
	printf("%c",'x');
}

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

using namespace std;

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A, *B;
	
	int C[VMAX+ 1];
	int n, i, j;
	scanf("%d", &n);
	
	A = malloc(sizeof(short) * n + 1);
	B = malloc(sizeof(short) * n + 1);
	
	for( i=0; i<=VMAX; i++ ) C[i] =0;
	
	for(i=0; i<n; i++){
		scanf("%hu", &A[i + 1]);
		C[A[i + 1]]++;
	}
	
	for ( i=1; i<=VMAX; i++ ) C[i] = C[i] + C[i-1];
	
	for( j=1; j<=n; j++){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for( i=1; i<=n; i++){
		if( i>1 ) printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 9612
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        List<Character> removedX = new ArrayList<>();
        int N = S.length();
        boolean[] isX = new boolean[N];
        for (int i = 0; i < N; i++) {
            if (S.charAt(i) == 'x') {
                isX[i] = true;
            } else {
               removedX.add(S.charAt(i));
            }
        }
        int rN = removedX.size();
        for (int i = 0; i < rN / 2; i++) {
            if (removedX.get(i) != removedX.get(rN - i - 1)) {
                System.out.println(-1);
                return;
            }
        }
        int ans = 0;
        int head = 0;
        int foot = N - 1;
        while (foot - head > 0) {
            if (isX[head] == isX[foot]) {
                head++;
                foot--;
            } else if (isX[head] && !isX[foot]) {
                head++;
                ans++;
            } else {
                foot--;
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24532
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
 
#include <thread>
#include <unordered_set>
#include <vector>
#include <memory.h>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <stdio.h>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <random>
#include <string>
#include <cassert>


#define getcx _getchar_nolock

using namespace std;
 
namespace std
{
	string to_string(string const& s) { return '"' + s + '"'; }
	string to_string(char c) { return string(1, c); }
	string to_string(const char* s) { return to_string((string)s); }
	string to_string(bool b) { return (b ? "true" : "false"); }
 
	template <class T1, class T2>
	string to_string(pair<T1, T2> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
 
	template <class T>
	string to_string(T c)
	{
		string s = "[";
		for (auto vvv : c) { s += to_string(vvv) + ","; }
		s += "]";
		return s;
	}
 
	void debug_impl() { cerr << endl; };
 
	template <typename T1, typename... T2>
	void debug_impl(T1 a, T2 ... b)
	{
		cerr << " " << to_string(a);
		debug_impl(b...);
	}
}
 
template <typename T>
struct reversion_wrapper
{
	T& iterable;
};
 
template <typename T>
auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); }
 
template <typename T>
auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); }
 
template <typename T>
reversion_wrapper<T> reverse(T&& iterable) { return { iterable }; }
 
 
#ifdef __ASD__
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_impl(__VA_ARGS__)
//#define endl "\n"
#else
#define dbg(...) ;
//#define endl "\n"
#endif
 
#define lng long long


int main()
{
#ifdef __ASD__
	auto start_t = chrono::steady_clock::now();
	freopen("input.txt", "r", stdin);
	//freopen("nul", "w", stderr);
	//freopen("output.txt", "w",  stdout);
#else
	ios_base::sync_with_stdio(false);
#endif

	int n;
	cin >> n;

	vector<int> b(n-1);
	vector<int> a(n);
	for(int i=0;i<n-1;i++)cin>>b[i];


	a.back()=b.back();

	for(int i=n-2;i>0;i--)
	{
		a[i]=min(b[i],b[i-1]);
	}

	a[0]=b[0];

	cout << accumulate(a.begin(), a.end(), 0) << endl;
	
#ifdef __ASD__
	auto finish_t = chrono::steady_clock::now();
	cerr << "Elapsed " << chrono::duration_cast<chrono::milliseconds>(finish_t - start_t).count() << " ms" << endl;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;
const int MAXM = 3e5+10;
const ll INF = 1e18;
int first[MAXN];
int idx;
int vis[MAXN];
ll dist[MAXN];
int n,m;
struct edge{
    int u,v,next;
    ll w;
}e[MAXM*2];
void add(int a,int b,ll c)
{
    e[idx].u = a;e[idx].v = b;
    e[idx].w = c;
    e[idx].next = first[a];
    first[a] = idx++;
}
struct node{
    int id;
    ll val;
    node(int a,ll b):id(a),val(b){}
    bool operator < (const node& t) const
    {
        return val>t.val;
    }
};
void init()
{
    fill(first,first+n+1,-1);
    idx = 1;
}
void dijkstra(int x)
{
    for(int i = 1;i <= n;i++){
        dist[i] = INF;
        vis[i] = 0;
    }
    priority_queue<node> q;
    q.push(node(x,0));
    dist[x] = 0;
    while(!q.empty()){
        node cur = q.top();
        q.pop();
        if(vis[cur.id]) continue;
        vis[cur.id] = 1;
        for(int i = first[cur.id];i!=-1;i=e[i].next){
            int v = e[i].v;
            if(dist[v]>dist[cur.id]+e[i].w){
                dist[v] = dist[cur.id]+e[i].w;
                q.push(node(v,dist[v]));
            }
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    init();
    for(int i = 1;i <= m;i++){
        int u,v;
        ll w;
        scanf("%d%d%lld",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }
    for(int i = 1;i <= n-1;i++){
        add(i+1,i,0);
    }
    dijkstra(1);
    if(dist[n] == INF){
        printf("-1\n");
    }
    else printf("%lld\n",dist[n]);
    return 0;
}


Measured memory_bytes: 13812
#include <stdio.h>

int weather_right_triangle(int, int, int);

int main(void)
{
	int n;
	scanf("%d", &n);
	int a[n][3];
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
		weather_right_triangle(a[i][0], a[i][1], a[i][2]);
	}
	return 0;
}

int weather_right_triangle(int a, int b, int c)
{
	if (a * a + b * b == c * c || 
		b * b + c * c == a * a || 
		a * a + c * c == b * b) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1016
#include <stdio.h>
int main(){
		long long int s,max,min,k; 
		int n;
		scanf("%d",&n);
		max = -1000000;
		min = 1000000;
		s = 0;
		for (int i=0; i<n ; ++i){
			scanf("%lld",&k);
				if(k>max) max = k;
				if(k<min) min = k;
				s =s+k;
		};
		printf("%lld %lld %lld\n",min ,max, s);
	    return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int count = 0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+10;
const int  mod=1e9+7;
int sum[maxn];
ll dp[110][5][5][5];
// n,i,j,k,h;
//A
int main()
{
    int n;
    ll ans=0;
    scanf("%d",&n);
    for(int i=0; i<4; i++)
        for(int j=0; j<4; j++)
            for(int k=0; k<4; k++)
            {
                if(i==0&&j==1&&k==2||i==0&&j==2&&k==1||i==2&&j==0&&k==1)
                    continue;
                dp[3][i][j][k]=1;

            }
    for(int t=4; t<=n; t++)
        for(int i=0; i<4; i++)
            for(int j=0; j<4; j++)
                for(int k=0; k<4; k++)
                    for(int h=0; h<4; h++)
                    {
                        if(i==0&&j==1&&k==2||i==0&&j==2&&k==1||i==2&&j==0&&k==1)
                            continue;//i,j,k
                        if(j==0&&k==1&&h==2||j==0&&k==2&&h==1||j==2&&k==0&&h==1)
                            continue;
                        if(i==0&&k==2&&h==1||i==0&&j==2&&h==1)
                            continue;
                        dp[t][j][k][h]=(dp[t][j][k][h]+dp[t-1][i][j][k])%mod;
                    }
    for(int i=0; i<4; i++)
        for(int j=0; j<4; j++)
            for(int k=0; k<4; k++)
                ans+=(dp[n][i][j][k]);
    printf("%lld\n",ans%mod);

    return 0;
}


Measured memory_bytes: 384
import math
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a.sort()
num = 10**6+10
input_list = defaultdict(int)
sqrt = math.sqrt(num)

ans = 0
for serial in a:



    if input_list[serial] == 1:
        # print(serial)
        continue
    if input_list[serial] == 2:
        # print(serial)
        ans -= 1
        input_list[serial] = 1
        continue
    input_list[serial] = 2
    for s in range(serial*2, num, serial): 
        input_list[s] =1
    ans +=1
# for i in a:
    # print(i,input_list[i])
print(ans)

Measured memory_bytes: 176748
#include <iostream>

using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;
	
	if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10)
	{
		if(y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	else if(x == 4 || x == 6 || x == 9)
	{
		if(y == 6 || y == 9 || y == 11)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

S = s()

score = 0

if S[0] == 'p':
    score -= 1
g = 1
p = 0
for c in S[1:]:
    if p < g:
        p += 1
        if c == 'g':
            score += 1
    else:
        g += 1
        if c == 'p':
            score -= 1

print score


Measured memory_bytes: 14316
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	for(int i=0;i<8;i++)
	{
		int ans=s[0]-'0';
		for(int j=0;j<3;j++)
		{
			if(i&(1<<j))
			ans=ans+s[j+1]-'0';
			else
			ans=ans-s[j+1]+'0';
		}
		if(ans==7)
		{
			cout<<s[0];
			for(int j=0;j<3;j++)
			{
				if(i&(1<<j))
				cout<<'+';
				else
				cout<<'-';
				cout<<s[j+1];
			}
			cout<<"=7";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
//
// Created by MengHaitao on 2019/11/27 0027.
//
//Select Sort
#include <iostream>

using namespace std;
int arr[1005], n, count;

void swap(int &a, int &b) { a ^= b ^= a ^= b; }   //交换两个数
void bubbleSort() {
    for (int i = 0; i < n; ++i) {
        int min = i;
        for (int j = i + 1; j < n; ++j) {
            if (arr[min] > arr[j]) {
                min = j;
            }
        }
        if (i != min) {
            swap(arr[i], arr[min]);
            count++;
        }

    }
    for (int j = 0; j < n; ++j) {
        if (j == n - 1) cout << arr[j] << endl;
        else
            cout << arr[j] << " ";
    }
    cout << count << endl;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    bubbleSort();
}

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


Measured memory_bytes: 3096
#include<stdio.h>
#define REP(i,n) for (int i = 0 ; i < (int)n ; i++)
typedef long long ll;

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int a[n][m];
    int b[m];
    int c[n];

    REP(i,n){
        REP(j,m){
            scanf("%d",&a[i][j]);
        }
        c[i] = 0;
    }
    REP(i,m){
        scanf("%d",&b[i]);
        
    }

    REP(i,n){
        REP(j,m){
            c[i] += (a[i][j] * b[j]);
        }
        printf("%d\n",c[i]);
    }
}


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

int main()
{
  long long n,m;
  cin >>n>>m;
  vector<int>a(n);
  long long sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  if(n <sum){
    cout<<-1<<endl;
    return 0;
  }else{
    cout<<n-sum<<endl;
    return 0;
  }

}

Measured memory_bytes: 7168
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    x = 1
    n = 0
    while 1:
        x = A[x-1]
        n += 1
        if x == 2:
            print(n)
            return
        if n > N:
            print(-1)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 7084
#include<stdio.h>
#include<string.h>
 
#define N 20000
 
typedef struct Data{
  int area,pos;
} Data;
 
Data t[N];
int u[N]; 
int n,i;
char str[N];
int T,U;
int ans,A;
Data B,X;
 
void D_push(Data );
Data D_pop();
void push(int);
int pop();
void init();
Data makeData(int,int);
 
 
int main(){
   
  init();
   
  scanf("%s",str);
   
  n = strlen(str);
   
  for(i = 0;i < n;i++){
     
    if(str[i] == '/'){
       
      if(U == 0)continue;
      A = pop();
      X = makeData(i-A,A);
      ans = ans + i - A;
      while(T > 0){
    B = D_pop();
    if(B.pos < A){
      D_push(B);
      break;
    }
    X.area = X.area + B.area;
    if(B.pos < X.pos)X.pos = B.pos;
      }
      D_push(X);
    }else if(str[i] == '\\'){
      push(i);
    }
     
  }
   
  printf("%d\n%d", ans, T);
  for(i = 0;i < T;i++){
    printf(" %d",t[i].area);
  }
  printf("\n");
  return 0;
}
 
void D_push(Data data){
  t[T++]=data;
}
 
Data D_pop(){
  return t[--T];
}
 
void push(int x){
  u[U++]=x;
}
 
int pop(){
  return u[--U];
}
 
 
void init(){
   
  ans=0;
  T=0;
  U=0;
   
}
 
Data makeData(int x,int y){
   
  Data res;
   
  res.area=x;
  res.pos=y;
   
  return res;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long L[100] = {0};

long long luca(long long n){
	if(L[n] > 0){
		return L[n];
	}
	if(n == 0){
		L[0] = 2;
		return 2;
	}
	if(n == 1){
		L[1] = 1;
		return 1;
	}
	long long ret = luca(n-1) + luca(n-2);
	L[n] = ret;
	return ret;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long N;
	cin >> N;

	long long ans = luca(N);
	printf("%lld\n", ans);
	return 0;
}

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

int main() {

  ll N,tmp;
  cin >> N;

  vector<ll> A(N);

  for(ll i=0; i<A.size()-1; i++){
    cin >> tmp;
    A[tmp-1]++;
  }

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


}


Measured memory_bytes: 4788
#include <stdio.h>
int main(void) 
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);

    int train=0;

    if(a<b) {
        train = a;
    } else {
        train = b;
    }

    int bus = 0;

    if (c < d) {
        bus = c;
    } else {
        bus = d;
    }

    int answer = train + bus;

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

Measured memory_bytes: 128
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
  int n, m;
  cin >> n >> m;
  if(n - m != 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int count = 0;

    for (int i = 0; i <= 3000; ++i) {
        if (R*i > N) break;
        for (int j = 0; j <= 3000; ++j) {
            if (R*i + G*j > N) break;
            if ((N - (R*i + G*j)) % B == 0) count++;
        }
    }

    cout << count << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int gcd(int x, int y){
  if(y==0)return x;
  return gcd(y,x%y);
}

int cnter(int n){
  int cnt = 0;
  while(n&&n%2==0){
    cnt++;
    n/=2;
  }
  return cnt;
}

int main(){
  string s; cin >> s;
  for(int i = 0; i < 26; ++i){
    bool f = false;
    for(auto e:s){
      f |= e == char(i+'a');
    }
    if(!f){
      cout << char(i+'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
} 


Measured memory_bytes: 3736
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
set<pair<int,string> > t;
string s[200010];
map<string,int> mp;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		mp[s[i]]++;
	}
	for(int i=0;i<n;i++){
		t.insert(make_pair(-mp[s[i]],s[i]));
	}
	pair<int,string> st=*t.begin();
	int last=st.first;
	for(set<pair<int,string> >::iterator it=t.begin();it!=t.end();it++){
		pair<int,string> p=*it;
		if(p.first!=last)break;
		else cout<<p.second<<endl;
		last=p.first;
	}
	return 0;
	return 0;
}

Measured memory_bytes: 39296
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String S = input.next();
		int N = S.length();
		int[] ans = new int[N];
		int curIndex = 0;
		while (curIndex < N) {
			int numLeft = 0;
			int numRight = 0;
			while (S.charAt(curIndex)=='R') {
				numRight++;
				curIndex++;
				if (curIndex==N) break;
			}
			//curIndex--; //After last ever L/R, curIndex is incremented which causes array 
			//out of bounds
			int R = curIndex-1;
			while (S.charAt(curIndex)=='L') {
				numLeft++;
				curIndex++;
				if (curIndex==N) break;
			}
			int left = numLeft;
			int right = numRight;
			if ((left+right)%2==0) { //Children cascade into adjacent numbers as close to 
				//each other as possible
				int sum = left+right;
				left=sum/2;
				right=sum/2;
			}else {
				int sum = left+right;
				if (right%2==1) { //The greater number is given to the R/L count with odd parity
					right=sum/2;
					left=sum-right;
				}else {
					left=sum/2;
					right=sum-left;
				}
			}
			ans[R]=left;
			ans[R+1]=right; //Children moving swaps squares 
			if (curIndex==N-1) break;
		}
		for (int i = 0; i < N; i++)
			System.out.print(ans[i]+" ");
	}
}

Measured memory_bytes: 41644
import os
import sys

import numpy as np


def solve(inp):
    def bitree_sum(bit, t, i):
        s = 0
        while i > 0:
            s += bit[t, i]
            i ^= i & -i
        return s

    def bitree_add(bit, n, t, i, x):
        while i <= n:
            bit[t, i] += x
            i += i & -i

    def bitree_lower_bound(bit, n, d, t, x):
        sum_ = 0
        pos = 0
        for i in range(d, -1, -1):
            k = pos + (1 << i)
            if k <= n and sum_ + bit[t, k] < x:
                sum_ += bit[t, k]
                pos += 1 << i
        return pos + 1

    def initial_score(d, ccc, sss, ttt):
        bit_n = d + 3
        bit = np.zeros((26, bit_n), dtype=np.int64)
        INF = 10 ** 18
        for t in range(26):
            bitree_add(bit, bit_n, t, bit_n - 1, INF)

        last = np.full(26, -1, dtype=np.int64)
        score = 0

        for i in range(d):
            t = ttt[i]
            score += sss[i, t]
            for u in range(26):
                if u == t:
                    continue
                score -= ccc[u] * (i - last[u])
            last[t] = i
            bitree_add(bit, bit_n, t, i + 2, 1)

        return bit, score

    def update_score(bit, bit_n, bit_d, ccc, sss, ttt, d, q):
        diff = 0
        t = ttt[d]
        k = bitree_sum(bit, t, d + 2)
        c = bitree_lower_bound(bit, bit_n, bit_d, t, k - 1) - 2
        e = bitree_lower_bound(bit, bit_n, bit_d, t, k + 1) - 2
        b = ccc[t]
        diff -= b * (d - c) * (e - d)
        diff -= sss[d, t]

        k = bitree_sum(bit, q, d + 2)
        c = bitree_lower_bound(bit, bit_n, bit_d, q, k) - 2
        e = bitree_lower_bound(bit, bit_n, bit_d, q, k + 1) - 2
        b = ccc[q]
        diff += b * (d - c) * (e - d)
        diff += sss[d, q]

        return diff

    d = inp[0]
    ccc = inp[1:27]
    sss = np.zeros((d, 26), dtype=np.int64)
    for r in range(d):
        sss[r] = inp[27 + r * 26:27 + (r + 1) * 26]

    ttt = np.random.choice(26, d)

    bit, score = initial_score(d, ccc, sss, ttt)
    bit_n = d + 3
    bit_d = int(np.log2(bit_n))

    for _ in range(5 * 10 ** 6):
        cd = np.random.randint(0, d)
        ct = np.random.randint(0, 26)
        diff = update_score(bit, bit_n, bit_d, ccc, sss, ttt, cd, ct)
        if diff > 0:
            score += diff
            bitree_add(bit, bit_n, ttt[cd], cd + 2, -1)
            bitree_add(bit, bit_n, ct, cd + 2, 1)
            ttt[cd] = ct

    return ttt + 1


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))


Measured memory_bytes: 27536
#include <bits/stdc++.h>
using namespace std;
 
#define EPS (1e-9)
#define ll long long int
#define ull unsigned long long
#define pi (acos(-1.0))
#define endl "\n"
#define all(v) v.begin(),v.end()
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?'\n':' ')
#define precise(n) cout << fixed << setprecision(n)
#define show(a) cout << (#a) << " is " << (a) << endl;
#define pcase cout<<"Case "<<++cs<<": "
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int mod=1e9+7;
const int mx=1e5+10;
 ll inf=1e14+5;
ll binpow(ll base, ll exp){ll res = 1;while(1){ if(exp&1) res*=base;exp>>=1;if(!exp)break;base*=base;}return res;}
ll dp[3005][3005];
vector< ll > v(3005);
int n,m,k;
ll func(int i,int j)
{
	//cout << "called "<< i << " and " <<j << endl; 
	if(i>n || j<1) return 0;
	if(i==j) return dp[i][j]=v[i];
	if(dp[i][j]!=inf) return dp[i][j];
	
	return dp[i][j]=max(v[i]-func(i+1,j),v[j]-func(i,j-1));
}
int main()
{
	FAST;
	
	cin >> n;
	
	for (int i=1;i<=n;i++)
	{
		cin >> v[i];
		
	}
	
	for (int i=0;i<=n;i++)
	{
		for (int j=0;j<=n;j++)
		{
			dp[i][j]=inf;
		}
	}
	//for (int i=0;i<=n;i++)
	//{
		//for (int j=0;j<=n;j++)
		//{
			//cout << "dp["<<i<< "]["<<j <<"] = " << dp[i][j] << endl;
		//}
		
	//}
	
	
		
		cout << func(1,n) << endl;
	
	
	
	
	return 0;
}


Measured memory_bytes: 70912
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define INF 2147483647
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
	string s;
	cin>>s;
	ll ans=0;
	for(int i=0;i<(1<<s.size()-1);i++){
		ll num=1,co=0;
		//cout<<bitset<10>(i)<<" ";
		for(int j=s.size()-1;j>=1;j--){
			
			co++;
			if(co!=1)num*=10;
			
			ans+=(s[j]-'0')*num;
			
			if(i & (1<<s.size()-1-j)){
				if(j==1)ans+=(s[j-1]-'0');
				num=1;
				co=0;
			}
			else if(j==1)ans+=(s[j-1]-'0')*num*10;
			
		}
		//cout<<ans<<endl;
	}
	if(s.size()==1)ans+=s[0]-'0';
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int A,B;
while(cin >> A >> B) cout << (A*B)/2 << endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define cins(s,n) rep(i,n)cin>>s.at[i];
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{
    int k;cin>>k;
    int p[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<p[k-1];
}

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

using namespace std;

long long inf=1000000007;

pair<int,int> mp(int a,int b){
	return make_pair(a,b);
}

int main(){
	int h,w;
	cin>>h>>w;
	vector<string> graph(h);
	int white=h*w;
	for(int i=0;i<h;i++){
		cin>>graph.at(i);
		for(auto a:graph.at(i)){
			if(a=='#') white--;
		}
	}

	vector<vector<int>> dist(h,vector<int>(w,-1));
	queue<pair<int,int>> que;
	que.push(mp(0,0));
	dist.at(0).at(0)=1;
	int cnt=-1;

	while(!que.empty()){
		int x=que.front().first;
		int y=que.front().second;
		que.pop();
		if(graph.at(y).at(x)=='#') continue;

		if(x==w-1 && y==h-1) cnt=dist.at(y).at(x);

		vector<int> dx={1,-1,0,0};
		vector<int> dy={0,0,1,-1};

		for(int i=0;i<4;i++){
			int a=x+dx.at(i);
			int b=y+dy.at(i);
			if(a>=0 && a<w && b>=0 && b<h && dist.at(b).at(a)==-1){
				dist.at(b).at(a)=dist.at(y).at(x)+1;
				que.push(mp(a,b));
			}
		}
	}

	cout<<(cnt!=-1 ? white-cnt : -1)<<endl;

	return 0;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  for (int i = -(N-1); i < N; i++) {
    cout << X + i;
    if (i < N-1) {
      cout << ' ';
    } else {
      cout << endl;
    }
  }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  string s, t;
  cin >> s >> t;
  if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
  {
    cout << "YES";
  }
  else
  {
    cout << "NO";
  }
  
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, a[200005], tops = 0;
ll f[200005], g[200005], ans = infll;
struct Node {int u, d;} stk[200005];

int main(){
	getint(N);
	for(register int i = 1; i <= N; i++) getint(a[i]);
	for(register int i = 2; i <= N; i++){
		f[i] = f[i - 1]; ll pre = a[i - 1], cur = a[i];
		while(pre < cur){
			pre <<= 2;
			if(!tops) f[i] += i - 1 << 1;
			else{
				Node p = stk[tops--];
				f[i] += i - p.u << 1;
				if(--p.d) stk[++tops] = p;
			}
		}
		int d = 0;
		while((cur << 2) <= pre) cur <<= 2, ++d;
		if(d) stk[++tops] = (Node){i, d};
	}
	tops = 0;
	for(register int i = N - 1; i >= 1; i--){
		g[i] = g[i + 1]; ll pre = a[i + 1], cur = a[i];
		while(pre < cur){
			pre <<= 2;
			if(!tops) g[i] += N - i << 1;
			else{
				Node p = stk[tops--];
				g[i] += p.u - i << 1;
				if(--p.d) stk[++tops] = p;
			}
			
		}
		int d = 0;
		while((cur << 2) <= pre) cur <<= 2, ++d;
		if(d) stk[++tops] = (Node){i, d};
	}
	for(register int i = 0; i <= N; i++) ans = min(ans, i + f[i] + g[i + 1]);
	return printf("%lld\n", ans), 0;
}

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

int main()
{
	long long A, B, C, K;
	cin >> A >> B >> C >> K;

	long long ans = (A - B) * pow(-1, K % 2);

	if (abs(ans) > pow(10, 18)) {
		cout << "Unfair" << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
static const int NMAX=10000;
static const int QMAX=500;
int search(int A[],int n,int key){
	int i = 0;
	A[n] = key;
	while( A[i] != key ) i++;
	return i != n;
}

int main(){
	int n,q;
	int key;
	int S[NMAX+1];
	int c=0;

	std::cin >> n;
	for(int i=0;i < n;i++){
		std::cin >> S[i];
	}
	std::cin >> q;

	for(int i=0;i < q;i++){
		scanf("%d",&key);
		if(search(S,n,key))c++;
	}

	std::cout << c << std::endl;
	return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'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'};
char moji2[26]={'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'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

int n;
vector<int> child[1005];
int X[1005];
bool dp[1005][5005];




int DFS(int v){
    if(child[v].size() == 0) return 0;

    vector< pair<int,int>> sum_of_child;
    int summ = 0;
    itrfor(itr,child[v]){
        int res = DFS(*itr);
        if(res == -1){
            return - 1;
        }
        sum_of_child.push_back( mp(X[*itr], res) ); 
        summ += X[*itr] + res;
    }

    int tmpn = sum_of_child.size();
    REP(i,tmpn + 1) REP(j,5005) dp[i][j] = false;
    dp[0][0] = true;

    REP(i,tmpn){
        int w1 = sum_of_child[i].fi;
        int w2 = sum_of_child[i].se;
        REP(j,5005){
            if(j - w1 >= 0 and  dp[i][j-w1]) dp[i+1][j] = true;
            if(j - w2 >= 0 and  dp[i][j-w2]) dp[i+1][j] = true;
        }
    }

    int ma = -1;
    REPR(i,X[v]){
        if(dp[tmpn][i]){
            ma =i;
            break;
        }
    }
    int ret = summ - ma;
    if(ma == -1) return -1;
    else return ret;





}


signed main(){
    cin >> n;
    FOR(i,1,n){
        int parent;
        cin >> parent;
        parent--;
        child[parent].push_back(i);
    }
    REP(i,n) cin >> X[i];
    if(DFS(0) == -1) cout << "IMPOSSIBLE" << endl;
    else cout << "POSSIBLE" << endl;
}

Measured memory_bytes: 5248
#include <cstring>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <set>

using namespace std;

int n;
int a[200000];

int dp[200000][2];

int solve(int pos, int prev){
  if(pos == n) return 0;
  if(dp[pos][prev] != -1) return dp[pos][prev];

  int col = a[pos];

  int res = 2000000;
  if(prev == 0){
    res = min(res, solve(pos + 1, col));
    res = min(res, solve(pos + 1, 1 - col) + 1);
  }else{
    if(col == 0) res = min(res, solve(pos + 1, 1) + 1);
    else res = min(res, solve(pos + 1, 1));
  }
  return dp[pos][prev] = res;
}

int main(){
  string s;
  cin >> n >> s;
  REP(i,n) a[i] = (s[i] == '#' ? 1 : 0);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", solve(0, 0));
  return 0;
}

Measured memory_bytes: 12292
n,k = map(int,input().split())
w = []
for _ in range(n):
    w.append(int(input()))

def enough(p,k,w):
    count = 0
    in_truck = 0
    for x in w:
        if x > p:
            return False
        else:
            if in_truck + x > p:
                count += 1
                in_truck = x
            else:
                in_truck += x
    if in_truck > 0:
        count += 1
    return k >= count

maximum = sum(w)
minimum = 1

while True:
    if minimum == maximum:
        break
    else:
        tmpp = (maximum + minimum) // 2
        if enough(tmpp,k,w):
            maximum = tmpp
        else:
            minimum = tmpp + 1

print(minimum)


Measured memory_bytes: 9556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(all(a));
  ll h = 0, w = 0;
  for (ll i = 0; i < n - 1; i++) {
    if (a[n - 1 - i] == a[n - 2 - i]) {
      h = a[n - 1 - i];
      for (ll j = i + 2; j < n - 1; j++) {
        if (a[n - 1 - j] == a[n - 2 - j]) {
          w = a[n - 1 - j];
          break;
        }
      }
      break;
    }
  }
  cout << h * w << endl;
}

Measured memory_bytes: 1024
#include <iostream>

int main(){
int a,b,z;
char op;

while(1){
	std::cin >> a >> op >> b;

	if( op == '?'){
		break;
	}

	if( op == '+' ){
		z=a+b;
	}
	else if( op == '-'){
		z=a-b;
	}
	else if( op == '*'){
		z=a*b;
	}
	else if( op == '/'){
		z=a/b;
	}
	std::cout << z << std::endl;
}



return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<queue>

const static int MAX = 100;
const static int INF = 1001001001;
int A[MAX][MAX];
int d[MAX];
int p[MAX];
int color[MAX];

int main(void){
    int n, u, k, v, c, mincost, sum;
    std::cin >> n;
    for(int i = 0; i < n; i++){
	for(int j = 0; j < n; j++){
	    A[i][j] = INF;
	}
    }
    for(int i = 0; i < n; i++){
	std::cin >> u >> k;
	for(int j = 0; j < k; j++){
	    std::cin >> v >> c;
	    A[u][v] = c;
	}
    }

    d[0] = 0;
    for(int i = 1; i < n; i++){
	d[i] = INF;
    }
    p[0] = -1;
    for(int i = 0; i < n; i++){
	color[i] = 0;
    }

    while(true){
	mincost = INF;
	for(int i = 0; i < n; i++){
	    if(mincost > d[i] && color[i] == 0){
		mincost = d[i];
		u = i;
	    }
	}
	color[u] = 1;

	if(mincost == INF) break;

	for(int i = 0; i < n; i++){
	    if(d[i] > d[u] + A[u][i] && color[i] == 0){
		d[i] = d[u] + A[u][i];
		p[i] = u;
	    }
	}
    }

    sum = 0;
    for(int i = 0; i < n; i++){
	color[i] = 0;
    }
    for(int i = 0; i < n; i++){
	int cur = i;
	while(p[cur] != -1 && color[cur] == 0){
	    sum += A[p[cur]][cur];
	    color[cur] = 1;
	    cur = p[cur];
	}
    }
    for(int i = 0; i < n; i++){
	std::cout << i << " " << d[i] << std::endl;
    }



    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int nxt[MAXN];

int main() 
{
    fastio();

    int n,m;
    string s;
    cin>>n>>m>>s;

    memset(nxt,-1,sizeof(nxt));

    deque<int>dq{0};
    int f = 0;
    for(int i=1;i<=n;i++)
    {
        if( s[i] == '1' )
            continue;

        while( !dq.empty() && i - dq.front() > m )
            dq.pop_front();

        if( !dq.empty() )
        {
            nxt[i] = dq.front();
        }
        else
        {
            f = 1;
        }

        if( s[i] == '0' )
            dq.push_back(i);
    }

    if( f )
    {
        cout<<-1;
        return 0;
    }

    int now = n;
    stack<int>ans;
    while( now > 0 )
    {
        int next = nxt[now];
        ans.push(now-next);
        now = next;
    }

    while( !ans.empty() )
    {
        cout<<ans.top()<<" ";
        ans.pop();
    }

    return 0;
}

Measured memory_bytes: 1308
var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");

  arr = input[0].split(" ");
  var n = parseInt(arr[0], 10);
  var m = parseInt(arr[1], 10);

  for (i = 0; i < n; i++) {
    arr[i] = input[i + 1].split(" ");
  }

  var vec = [];
  for (i = n; i < n + m; i++) {
    vec[i - n] = input[i + 1]
  }

  var sarr = new Array(n);
  for (i = 0; i < n; i++) {
    sarr[i] = 0;
    for (j = 0; j < m; j++) {
      sarr[i] += arr[i][j] * vec[j];
    }
  }

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

Measured memory_bytes: 10320
#include<stdio.h>
int main(void)
{
	double a,b,c,d,e,f,x,y;
	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
	{
		x = ((c*e)-(b*f))/((a*e)-(b*d));
		y = (c-a*x)/b;
		if(x == -0.0) x = 0;
		if(y == -0.0) y = 0;
		printf("%.3lf %.3lf\n",x,y);

		
	}
	return 0;
}

Measured memory_bytes: 652
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <string>
#include <cmath>
//#include <vector>
//#include <time.h>
#include <queue>
//#include <stack>
//#include <map>
//#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=i;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    print $ solve n
    main

solve :: Int -> Int
solve n | null ys' = head zs - last xs
        | otherwise = 0
  where (xs, ys) = span (< n) ps
        (ys', zs) = break (> n) ys


isP :: Int -> Bool
isP x = all ((/= 0).(mod x)) . takeWhile ((<= x).(^ 2)) $ ps

ps :: [Int]
ps = 2 : unfoldr f 3
  where f x | isP x = Just (x, x+2)
            | otherwise = f (x+2)



Measured memory_bytes: 22584
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vdouble = vector<double>;

int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int main(){
	ll N,K,sum=0;
	cin>>N>>K;
	vll H(N);
	REP(i,N) cin>>H[i];
	
	VSORT(H);
	VREV(H);
	
	FOR(i,K,N){
		sum+=H[i];
	}
	
	cout<<sum<<endl;
	
}

Measured memory_bytes: 1792
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
for i in range(N):
  a[i],b[i]=map(int,input().split())
#print(a)
#print(b)

b.sort(reverse=True)
maxa=max(a)
#print(max(a))
#print(b)

ans=0
for i in range(N):
  if b[i]<maxa:
    break
  if H<=0:
    break
  H-=b[i]
  ans+=1
if H>0:
  ans+=-(-H//maxa)
print(ans)

Measured memory_bytes: 11312
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int a,b,x;

  cin >> a >> b >> x;

  a = min(a, b*2);

  cout << min((x+999)/1000 * a, x/1000 * a + (x%1000+499)/500 * b) << endl;
  
  return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  //acceleration
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  //initialization
  long long int a;
  double b;
  cin >> a >> b;
  
  long long int c = round(b * 100); 
  long long int d = a * c / 100;
  cout << (long long int)d << "\n";
}

Measured memory_bytes: 3792
#include<stdio.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
int count(int i,char s[1000][1052]){
    int ans=0;
    for(int j=0;;j++){
        if(s[i][j]==' '){
            ans++;
        }
        else{
            break;
        }
    }
    return ans;
}
/*void space(int i,char s[1000][1052]){
    for(int j=0;j<1052;j++){
        if(s[i][j]=='.'){
            s[i][j]=' ';
        }
    }
}*/
void space(int i,char s[1000][1052]){
    for(int j=0;;j++){
        if(s[i][j]=='.'){
            s[i][j]=' ';
        }
        else{
            break;
        }
    }
}
char s[1000][1052]={0};
int main(void){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0) break;
        getchar();
        rep(i,n) fgets(s[i],1052,stdin);
        rep(i,n) space(i,s);
        //rep(i,n) printf("%s",s[i]);
        for(int i=1;i<n;i++){
            int idx=count(i,s);
            s[i][idx-1]='+';
            //直信
            if(count(i-1,s)<=idx-1);
            else{
                for(int j=i-1;j>=0;j--){
                    if(s[j][idx-1]=='+'){
                        break;
                    }else{
                        s[j][idx-1]='|';
                    }
                }
            }
        }
        rep(i,n) printf("%s",s[i]);
    }
}



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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n, vector<int>(n));
  vector<int> d(n);
  while (m--) {
    int u, v, f;
    cin >> u >> v >> f;
    --u, --v;
    g[u][v] = g[v][u] = f;
    ++d[u], ++d[v];
  }
  int res = 0;
  auto fn = [&](const auto& a) {
    int crr = 0;
    for (int v : a) {
      int mn = 1e9;
      for (int u : a) {
        if (u != v) {
          mn = min(mn, g[v][u]);
        }
      }
      crr += mn;
    }
    res = max(res, crr);
  };
  for (int k = 2; k < 20; ++k) {
    vector<int> vs;
    for (int v = 0; v < n; ++v) {
      if (d[v] >= k - 1) {
        vs.push_back(v);
      }
    }
    m = vs.size();
    if (m < k) {
      continue;
    }
    vector<int> p(m);
    fill(end(p) - k, end(p), 1);
    do {
      vector<int> a;
      for (int i = 0; i < m; ++i) {
        if (p[i]) {
          a.push_back(vs[i]);
        }
      }
      fn(a);
    } while (next_permutation(begin(p), end(p)));
  }
  cout << res << '\n';
}



Measured memory_bytes: 3260