akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    vector <ll> a(n);
    rep(i,0,n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    if (a[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll sum = 1;
    rep(i,0,n) {
        if (sum > (long long)pow(10,18) / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        sum *= a[i];
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;
   
    int total = 0;
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        total += P[i];
    }

    sort(P.begin(), P.end(), greater<int>());
    total -= P[0]/2;

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
import copy

def main():
    h,w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y,x = que.popleft()
            if x >0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x <w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y >0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
        if nque:
            que = copy.copy(nque)
        else:
            break
    print(count-1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 115492
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<int> canwthdrw(0);
    int a=1;
    canwthdrw.push_back(a);
    while(a*6<=100000){
        a *= 6;
        canwthdrw.push_back(a);
    }
    a = 1;
    while(a*9<=100000){
        a *= 9;
        canwthdrw.push_back(a);
    }
    sort(canwthdrw.begin(),canwthdrw.end());
    reverse(canwthdrw.begin(),canwthdrw.end());
    int n,ans=0;
    cin >> n;
    int dp[100000]={};
    for(int i=1;i<=n;i++){
        int b = 100000;
        for(int j=0;j<canwthdrw.size();j++){
            if(canwthdrw[j]<=i) b = min(b,dp[i-canwthdrw[j]]+1);
        }
        dp[i] = b;
    }
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
n = int(input())
w = [input() for i in range(n)]
count = 0
for i in range(1, n):
    if w[i - 1][len(w[i - 1]) - 1] != w[i][0]:
        count += 1
if count == 0 and len(list(set(w))) == n:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int dp[50][500][500];
const int INFTY = 1e9;

int main(){
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> A(N), B(N), C(N);
    int sum_a = 0, sum_b = 0;
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i] >> C[i];
        sum_a += A[i];
        sum_b += B[i];
    }

    fill((int*)dp[0][0], (int*)dp[50][0],INFTY);
    dp[0][0][0] = 0;

    for(int i=0;i<N;i++){
        for(int a=0;a<=sum_a;a++){
            for(int b=0;b<=sum_b;b++){
                if(dp[i][a][b] == INFTY) continue;
                dp[i+1][a+A[i]][b+B[i]] = min(dp[i+1][a+A[i]][b+B[i]], dp[i][a][b] + C[i]);
                dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b]);
            }
        }
    }

    int ans = INFTY;
    for(int a=1;a<=sum_a;a++){
        for(int b=1;b<=sum_b;b++){
            if(dp[N][a][b] == -1 || Ma*b != Mb*a) continue;

            ans = min(ans, dp[N][a][b]);
        }
    }
    if(ans == INFTY){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 49024
#include<stdio.h>
int main (void){
    int a,h,m,s;
    
    scanf("%d",&a);
    h = a / 3600;
    m = (a % 3600) / 60; 
    s = (a % 3600) % 60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;    
}


Measured memory_bytes: 2756
def main():
  a, b = map(int, input().split(' '))
# a ÷ b ： d (整数)
# a ÷ b の余り ： r (整数)
# a ÷ b ： f (浮動小数点数)

  d = a // b
  r = a % b
  f = a / b 
  
  print("{0} {1} {2:.8f}".format(d, r, f))

if __name__ == "__main__":
  main()


Measured memory_bytes: 5616
n, k = gets.split.map(&:to_i)
s = gets.chomp.split("")
gr = []
grsum = []
jd = s[0]
cnt = i = max = 0
s.each do |c|
  if c == jd
    cnt += 1
  else
    jd = c
    gr[i] = cnt
    cnt = 1
    i += 1
  end
end
gr[i] = cnt

grsum[0] = 0
for j in 1..(i+1)
  grsum[j] = grsum[j-1] + gr[j-1]
end
 
cnt = sta = en = 0
 
if s[0] == "0"
  en = k * 2 - 1
  en = i if en > i
  max = grsum[en+1]
  sta = 1
  sta = 0 if i == 0
end
while 1
  en = sta + 2 * k
  en = i if en > i
  cmp = grsum[en+1] - grsum[sta]
  max = cmp if max < cmp
  if en == i
    break
  end
  sta += 2
end
puts max

Measured memory_bytes: 8644
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long  a,b;
	cin>>a>>b;
	if(a==1&&b==1)cout<<1<<endl;
	else if(a==1)cout<<b-2<<endl;
	else if(b==1)cout<<a-2<<endl;
	else cout<<(a-2)*(b-2)<<endl;
	return 0;
}


Measured memory_bytes: 256
int zeller(int Y,int M,int D){if(++M<4)Y-=1,M+=12;int y=Y/100,z=y%100;return (21*y/4+5*z/4+13*M/5+D)%7;}
char *W[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
main(m,d){for(;scanf("%d%d",&m,&d),m;)puts(W[zeller(2004,m,d)]);exit(0);}

Measured memory_bytes: 1760
import sys
from heapq import heapify, heappop, heappush
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M = IL()
LRC = [IL() for _ in range(M)]

root = [[(0, i-1)] for i in range(N+1)] #(cost, vertex)
for i in range(M):
  L, R, C = LRC[i]
  root[L].append((C, R))
#print(root)
data = []
heappush(data, (0, 1)) #(total_cost, vertex)
ans = [MAX_INT]*(N+1)
ans[1] = 0
finished = [False]*(N+1)
finished[0] = True

while data:
  nowcost, v = heappop(data)
  #print(nowcost, v)
  if finished[v] == False:
    finished[v] = True
    for edge, nextv in root[v]:
      if ans[nextv] < nowcost + edge:
        continue
      else:
        ans[nextv] = nowcost + edge
        heappush(data, (nowcost + edge, nextv))
      #print(ans)
if finished[N] == True:
  print(ans[N])
else:
  print(-1)

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

int main() {
  int N, K=1,sum=0;
  cin >> N;
  int i=0,j=10;
  
  if(N/100000000>=1)
    K=9;
  else if(N/10000000>=1&&K==1)
    K=8;
  else if(N/1000000>=1&&K==1)
    K=7;
  else if(N/100000>=1&&K==1)
    K=6;
  else if(N/10000>=1&&K==1)
    K=5;
  else if(N/1000>=1&&K==1)
    K=4;
  else if(N/100>=1&&K==1)
    K=3;
  else if(N/10>=1&&K==1)
    K=2;
  
  while(i<K){
    sum+=(N%j)/(j/10);
    i++;
    j*=10;
  }
  
  if(N%sum==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

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

    if(N%2==1){
        cout << 0 << endl;
    }else{
        long long fac=10;
        while( fac<=N ){
            ans += (long long) N/fac;
            fac=5*fac;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();
        int n = sc.nextInt();
        int m = s.length();


        for(int i = 0;i < m;i++){//i=0,1,2,,,,n-1 で動作
            if(i%n == 0)
                System.out.print(s.charAt(i));
        }



//        System.out.println(ans);
    }
}

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

int main(){
  int64_t N;
  cin >> N;
  int64_t ans=0;
  for(int i=1;i<=N;i++){
    for(int j=i;j<=N;j+=i){
      ans+=j;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector < vector <int> > a(n);
  vector <int> b(n,0);
  for (int i = 0; i < n; ++i){
	a[i] = b;
  }
  b.clear();
  vector <int> cnt(n-1, 0);
  for (int i = 0; i < n; ++i){
	for (int j = i+1; j < n; ++j){
		if (i < x){
			if (j <= x){
				a[i][j] = j - i;
			}else if (j >= y){
				a[i][j] = x - i + 1 + j - y;
			}else{
				a[i][j] = min(j - i, x - i + 1 + y - j);
			}
		}else if (i == x){
			if (j == y){
				a[i][j] = 1;
			}else if (j > y){
				a[i][j] = 1 + j - y;
			}else{
				a[i][j] = min(y - j + 1, j - i);
			}
		}else if (i == y){
			a[i][j] = j - i;
		}else if (i > y){
			a[i][j] = j - i;
		}else{
			if (j >= y){
				a[i][j] = min(j - i, i - x + 1 + j - y);
			}else{
				a[i][j] = min(j - i, i - x + 1 + y - j); 
			}
		}
		++cnt[ a[i][j] -1];	
	}
  }
 	for (int i : cnt){
		cout << i << "\n";
	}	
  
return 0;
}


Measured memory_bytes: 16000
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  s <- getLine
  putStrLn $ "2018" ++ drop 4 s


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

#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN3(a,b,q)
    vector<long long> s(a+2),t(b+2);
    s[0] = -1e11;
    t[0] = -1e11;
    rep(i,a) cin >> s[i+1];
    rep(i,b) cin >> t[i+1];
    s[a+1] = 1e11;
    t[b+1] = 1e11;
    
    rep(i,q){
        long long x;cin >> x;

        long long ss[2],tt[2]; 

        auto itr = lower_bound(s.begin(),s.end(),x);
        ss[0] = x-*(itr-1);
        ss[1] = *itr-x;
        
        itr = lower_bound(t.begin(),t.end(),x);
        tt[0] = x-*(itr-1);
        tt[1] = *itr-x;
        
        long long ans=LLONG_MAX;
        rep(i,2){
            rep(j,2){
                long long tmp = (i^j)?ss[i]+tt[j]:abs(ss[i]-tt[j]);
                ans = min({ans,ss[i]+tmp,tt[j]+tmp});
            }
        }
        cout << ans << endl;
    } 
}



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

def main():
    import copy
    h,w,K = map(int, input().split())
    c = [[] for _ in range(w)]
    for i in range(h):
        a = input()
        for j in range(w):
            c[j].append(a[j])
    #print(c)
    ans = 0
    for i in range(h):
        for j in range(w):
            C = copy.deepcopy(c)
            C[j].pop(i)
            ren = 0
            point = 0
            while True:
                cnt = 0
                for k in range(30,0,-1):
                    #print(k)
                    start = 0
                    while start <= w-K:
                        if (len(C[start]) < k):
                            start += 1
                            continue
                        num = C[start][-k]
                        end = start
                        while True:
                            #print(C,k,start,end)
                            if (end<w-1 and len(C[end+1])>=k and C[end+1][-k]==num):
                                end += 1
                            else:
                                break
                        if (end+1-start >= K):
                            point += (end+1-start)*int(C[start][-k])*(2**ren)
                            for p in range(start,end+1):
                                #print(C,p,k,start,end,point)
                                C[p].pop(-k)
                                cnt += 1
                        start = end + 1
                if (cnt == 0):
                    break
                ren += 1
            if (point > ans):
                ans = point
    print(ans)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 54492
#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

#define MAX 30

struct point{
	int x,y;
};

int n,m,g,d;
vector<int> amida[MAX+1];
char in;
point ans;


bool search(int x,int y,bool f){
	//cout<<x<<","<<y<<","<<f<<","<<ans.x<<","<<ans.y<<endl;
	bool ok=false;

	if(y==d+1){
		if(x==g){
			ok=true;
			if(f==false) ans.x=0,ans.y=0;
		}
	}
	else if(amida[y][x-1]==1){
		ok=search(x-1,y+1,f);
	}
	else if(amida[y][x]==1){
		ok=search(x+1,y+1,f);
	}
	else{
		ok=search(x,y+1,f);
		if(!f){
			if(x!=1&&(x==2||amida[y][x-2]==0)){
				ok=search(x-1,y+1,true);
				if(ok==true&&((ans.x==-1&&ans.y==-1)||ans.y>y)) ans.x=x-1,ans.y=y;
			}
			if(x!=n&&(x==n-1||amida[y][x+1]==0)){
				//cout<<x<<"."<<y<<endl;
				ok=search(x+1,y+1,true);
				//cout<<ok<<endl;
				if(ok==true&&((ans.x==-1&&ans.y==-1)||ans.y>y)) ans.x=x,ans.y=y;
			}
		}
	}
	return ok;
}

int main(){

	while(1){

		cin>>n;
		if(n==0) break;
		
		for(int i=0;i<=MAX;i++) if(!amida[i].empty()) amida[i].clear();

		cin>>m>>g>>d;

		getchar();
		for(int i=1;i<=d;i++){
			amida[i].push_back(0);
			for(int j=1;;j++){
				in=getchar();
				if(in=='\n') break;
				amida[i].push_back(in-'0');	
			}
			amida[i].push_back(0);
		}

		ans.x=-1,ans.y=-1;
		search(m,1,false);
		if(ans.x==-1&&ans.y==-1) cout<<"1"<<endl;
		else if(ans.x==0&&ans.y==0) cout<<"0"<<endl;
		else cout<<ans.y<<" "<<ans.x<<endl;
	}
}

Measured memory_bytes: 1220
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] list = Console.ReadLine().Split(' ');
            int a = int.Parse(list[0]);
            int b = int.Parse(list[1]);
            
            if (a >= 13)
            {
                Console.WriteLine(b);
            }
            else if (a >= 6 && a <= 12)
            {
                Console.WriteLine(b / 2);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}


Measured memory_bytes: 11092
H, W, K = map(int, input().split())
C = [[True if c == "#" else False for c in input()] for _ in range(H)]


def width_mask():
    ret_mask = [0] * W
    for i in range(2 ** W):
        for j in range(W):
            ret_mask[j] = (i & 1)
            i >>= 1
        yield ret_mask


def height_mask():
    ret_mask = [0] * H
    for i in range(2 ** H):
        for j in range(H):
            ret_mask[j] = (i & 1)
            i >>= 1
        yield ret_mask


ans = 0

for w_mask in width_mask():
    for h_mask in height_mask():
        count = 0
        for i in range(H):
            for j in range(W):
                if w_mask[j] == 1 and h_mask[i] == 1 and C[i][j]:
                    count += 1

        if count == K:
            ans += 1

print(ans)



Measured memory_bytes: 9236
n = gets.to_i
a = gets.split.map(&:to_i)
inv = 0
b = 100000000
a.each do |num|
    inv += b/num
end
puts (b*b/inv)/b.to_f

=begin
n,m = gets.split.map(&:to_i)
puts ">"*(m*7+3)+"<<<<<<<[#{">"*(n*7)}+#{"<"*(n*7)}-]"*m+">"*(n*7-3)+"+"*n+"[-[<<<<<<<+>>>>>>>-]<<<<"+">>>>>>>[<<<<<<<+>>>>>>>-]"*m+"<"*(m*7+2)+"+[>+>"+"[>+>>+<<<-]>>>[<<<+>>>-]<<[->[>>+<]>[<]>-[>>>>+<<<<<<++++++++++>>+]<<-<]>>>>>>"*(m+1)+">["+"<"*(m*7+10)+"->->"+"[>+>>+<<<-]>>>[<<<+>>>-]<<[->---------[>>+<]>[<]>-[>>>>+<<<<<<---------->>+]<<++++++++++<]>>>>>>"*(m+1)+">[-]]"+"<"*(m*7+10)+"]<]"


# a/b
# n = ceil(log_10 a)
# m = ceil(log_10 b)
# 
# a = a_0+a_1*10+......a_(n-1)*10**(n-1)
# b = b_0+b_1*10+......b_(n-1)*10**(m-1)
#
# 7 cells = 1 digit
# [*][][][b_0][][a_0][] [][][][b_1][][a_1][] ......
# 
# [*][][quo_0][][][rem_0][] [][][quo_1][][][rem_1][] ......

=end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    // TODO solve
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String n = scanner.next();
        final int k = scanner.nextInt();

        int justCount = 1;
        final long[][] less = new long[n.length()][k + 1];
        less[0][1] = n.charAt(0) - '1';
        less[0][0] = 1;
        for (int i = 1; i < n.length(); i++) {
            final int digit = n.charAt(i) - '0';
            if (digit != 0) {
                if (justCount < k) {
                    less[i][justCount + 1] += digit - 1;
                    less[i][justCount]++;
                } else if (justCount == k) {
                    less[i][justCount]++;
                }
                justCount++;
            }

            // less
            for (int j = 0; j <= k; j++) {
                // その桁が0
                less[i][j] += less[i - 1][j];
                if (j != 0) {
                    // その桁が1 ~ 9
                    less[i][j] += less[i - 1][j - 1] * 9;
                }
            }
        }

        System.out.println(less[n.length() - 1][k]+(justCount==k?1:0));
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=233,P=2333;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }

ll a,b,c,x,y,ans;

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	cin>>a>>b>>c>>x>>y;
	while(x>=1&&y>=1){
		ans+=min(c+c,a+b);
		--x,--y;
	}
	ans+=min(x*a+y*b,(c+c)*max(x,y));
	cout<<ans<<endl;
	return 0;
}

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

const int N = 1e5 + 7;
int dp[N], to[N];
bool arr[N];
set<pair<int, int>> act;
int n, m;
string str;

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

  cin >> n >> m >> str;
  for (int i = 0; i <= n; ++i) {
    arr[i] = str[i] == '0';
  }
  act.emplace(0, n);
  to[n] = n + 1;
  for (int i = n - 1; i >= 0; --i) {
    if (i + m + 1 <= n) {
      act.erase(pair<int, int>(dp[i + m + 1], i + m + 1));
    }
    if (!arr[i]) {
      continue;
    }
    if (act.empty()) {
      cout << -1 << "\n";
      return 0;
    }
    auto it = *act.begin();
    dp[i] = it.first + 1;
    to[i] = it.second;
    act.emplace(dp[i], i);
  }
  int ind = 0;
  while (ind < n) {
    cout << to[ind] - ind << " ";
    ind = to[ind];
  }
  cout << "\n";

  return 0;
}



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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll t=1;
ll n,x;
string s;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	ll n3 = n/3;
	ll n5 = n/5;
	ll n15 = n/15;
	ll ans = (n)*(n+1)/2 - 3*(n3)*(n3+1)/2 - 5*(n5) * (n5+1)/2 + 15*(n15) * (n15+1)/2;
	cout<<ans;newl;	
}

int main() {
	fastio;randomINT;
	//cin>>t;
	while(t--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 238032
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        String x[] = scanner.next().split("");
        String y[] = scanner.next().split("");



        String str = new String();
        for(int i = 0; i < n; i++) {
            str += x[i] + y[i];
        }

        System.out.println(str);
    }
}


Measured memory_bytes: 21716
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])

k = [0] * 60

for j in range(60):
    l = a & 1
    k[j] = np.count_nonzero(l)
    a >>= 1

ans = 0
c = 0
for d in k:
    ans += (d * (n - d) * 2**c)  % (10**9 + 7)
    c += 1
    
print(ans % (10**9 + 7))

Measured memory_bytes: 49920
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main(){
	fast;
	ll a,b,k;
	cin>>a>>b>>k;
	if(k>a)
	{
		k-=a;
		a=0;
	}
	else
	{
		a-=k;
		k=0;
	}
	if(k>b)
	{
		k-=b;
		b=0;
	}
	else
	{
		b-=k;
		k=0;
	}
	cout<<a<<" "<<b;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main() {
	int  n,taro=0,hanako=0,i;
	char t[101] = { 0 }, h[101] = {0};

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s %s", t, h);
		if (strcmp(t, h) > 0) {
			taro += 3;
		}
		else if (strcmp(t, h) < 0) {
			hanako += 3;
		}
		else {
			taro++; hanako++;
		}
	}

	printf("%d %d\n", taro, hanako);

	return 0;
}


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

//変数定義
int N;
int A[210];

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

	int res = 0;

	while(true){
		//奇数有無確認
		bool exist_odd = false;
		for (int i = 0; i < N; ++i){
			if (A[i] % 2 != 0) exist_odd = true;
		}

		//奇数ありでブレーク
		if (exist_odd) break;

		//奇数ありで操作
		for (int i = 0; i < N; ++i){
			A[i] /= 2;
		}

		//実行回数インクリ
		++res;
	}

	cout << res << endl;
}

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

long long n, m;

bool asc(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second > p2.second;
}

int main() {
  long long i, x, y, sum = 0, ans = 0;
  while(1) {
    cin >> n >> m;
    if(n + m == 0) break;
    sum = 0;
    ans = 0;
    vector<pair<long long, long long>> dp;
    for(i = 0; i < n; ++i) {
      cin >> x >> y;
      dp.push_back(make_pair(x, y));
    }
    sort(dp.begin(), dp.end(), asc);
    for(i = 0; i < n; ++i) {
      if(sum < m) {
        sum += dp[i].first;
        if(sum >= m) ans += (sum - m) * dp[i].second;
      }
      else
        ans += dp[i].first * dp[i].second;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3340
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

constexpr int64_t kMod = 1e9+7;

int main() {
  int64_t N;
  cin >> N;
  
  vector<int64_t> nums(N);
  vector<int64_t> sums(N+1);
  for (int64_t n = 0; n < N; ++n) {
    cin >> nums[n];
    sums[n+1] = sums[n] + nums[n];
  }
  int64_t sum = 0;
  for (int64_t n = 0; n < N-1; ++n) {
    (sum += ((sums.back() - sums[n+1]) % kMod) * nums[n]) %= kMod;
  }
  cout << sum << endl;
  
  return 0;
}


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

int main() {
 string eso;
 cin >> eso;
  if (eso == "SSS"){
    cout << 0;
  }
    if (eso == "RSS"){
    cout << 1;
  }
    if (eso == "SRS"){
    cout << 1;
  } if (eso == "SSR"){
    cout << 1;
  } if (eso == "SRR"){
    cout << 2;
  } if (eso == "RRS"){
    cout << 2;
  } if (eso == "RSR"){
    cout << 1;
  } if (eso == "RRR"){
    cout << 3;
  }
  
	return 0;
}

Measured memory_bytes: 3560
A = input()
op_cnt = len(A) - 1
result = 0
for i in range(2 ** op_cnt):
    f = ""
    bag = []
    for j in range(op_cnt):
        if (i >> j) & 1:
            bag.append("+")
        else:
            bag.append("-")
    for p_n, p_o in zip(A, bag + [""]):
        f += (p_n + p_o)
    if eval(f) == 7:
        print(f+'=7')
        break

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

int Puzzle[3][3];
int tmp[3][3];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void Empty(int *, int *);
void swap(int *, int *);
int Cal();
int DFS(int, int, int, int, int);

int main(){
  int i, j, l;
  int x, y, a;

  for(i = 0 ; i < 3 ; i++){
    for(j = 0 ; j < 3 ; j++){
      scanf("%d",&Puzzle[i][j]);
    }
  }

  Empty(&x,&y);

  for(l = 0 ; l < 100 ; l++){
    for(i = 0 ; i < 3 ; i++){
      for(j = 0 ; j < 3 ; j++){
	tmp[i][j] = Puzzle[i][j];
      }
    }

    a = DFS(x, y, -1, 0, l);
    if(a != -1){
      printf("%d\n",a);
      break;
    }

    for(i = 0 ; i < 3 ; i++){
      for(j = 0 ; j < 3 ; j++){
	Puzzle[i][j] = tmp[i][j];
      }
    }
    
    a = -1;
    if(l == 99) printf("%d\n",a);
  }

  return 0;
}

void Empty(int *x, int *y){
  int i, j;

  for(i = 0 ; i < 3 ; i++){
    for(j = 0 ; j < 3 ; j++){
      if(!Puzzle[i][j]){
	*x = j;
	*y = i;
	return;
      }
    }
  }
}

void swap(int *a, int *b){
  int tmp;
  
  tmp = *a;
  *a = *b;
  *b = tmp;
}


int Cal(){
  int i, a;
  int sum = 0;

  for(i = 0 ; i < 9 ; i++){
    a = Puzzle[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3)  + abs(i%3 - a%3);
    }
  }

  return sum;
}

int DFS(int x, int y, int p, int dep, int limit){
  int i, h, nx, ny, res;

  h = Cal();
  
  if(h == 0) return dep;
  if(dep + h > limit) return -1;

  for(i = 0 ; i < 4 ; i++){
    nx = x + dx[i];
    ny = y + dy[i];

    if(~p && i == (p+2)%4) continue;
    if(!(0 <= nx && nx < 3 && 0 <= ny && ny < 3)) continue;

    swap(&Puzzle[y][x], &Puzzle[ny][nx]);
    res = DFS(nx, ny, i, dep+1, limit);
    if(~res) return res;

    swap(&Puzzle[y][x], &Puzzle[ny][nx]);
  }

  return -1;
}
    



Measured memory_bytes: 2108
class Dice
  @north = 5
  @south = 2
  @east = 3
  @west = 4
  @top = 1
  @bottom = 6

  def initialize(input_t, input_s, input_e, input_w, input_n, input_b)
    @north = input_n
    @south = input_s
    @east = input_e
    @west = input_w
    @top = input_t
    @bottom = input_b
  end

  def move(order_array)
    length = order_array.length
    for i in 0..(length-1)
      if order_array[i] == "N"
        move_north
      elsif order_array[i] == "S"
        move_south
      elsif order_array[i] == "E"
        move_east
      else
        move_west
      end
    end
    output = [@north, @south, @east, @west, @top, @bottom]
    return output
  end

  def move_north
    tmp = []
    tmp.push(@north)
    tmp.push(@south)
    tmp.push(@top)
    tmp.push(@bottom)
    @bottom = tmp[0]
    @top = tmp[1]
    @north = tmp[2]
    @south = tmp[3]
  end

  def move_south
    tmp = []
    tmp.push(@north)
    tmp.push(@south)
    tmp.push(@top)
    tmp.push(@bottom)
    @top = tmp[0]
    @bottom = tmp[1]
    @south = tmp[2]
    @north = tmp[3]

  end

  def move_east
    tmp = []
    tmp.push(@east)
    tmp.push(@west)
    tmp.push(@top)
    tmp.push(@bottom)
    @bottom = tmp[0]
    @top = tmp[1]
    @east = tmp[2]
    @west = tmp[3]
  end

  def move_west
    tmp = []
    tmp.push(@east)
    tmp.push(@west)
    tmp.push(@top)
    tmp.push(@bottom)
    @top = tmp[0]
    @west = tmp[2]
    @bottom = tmp[1]
    @east = tmp[3]
  end

end

dice_numbers = gets.chomp.split.map(&:to_i)
input_t = dice_numbers[0]
input_s = dice_numbers[1]
input_e = dice_numbers[2]
input_w = dice_numbers[3]
input_n = dice_numbers[4]
input_b = dice_numbers[5]
dice = Dice.new(input_t, input_s, input_e, input_w, input_n, input_b)

q = gets.chomp.to_i
answers = []
for i in 0..(q-1)
  question = gets.chomp.split.map(&:to_i)
  top = question[0]
  south = question[1]
  loop do
    output =  dice.move(["N", "S", "E", "W"].sample)
    if output[4] == top && output[1] == south
      answers.push(output[2])
      break
    end
  end
end

for i in 0..(q-1)
  puts answers[i]
end

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    string succ(string s) {
        if (s.empty()) return "a";
        char c = s[s.size() - 1];
        if (c == 'z') {
            return succ(s.substr(0, s.size() - 1)) + "a";
        } else {
            return s.substr(0, s.size() - 1) + string(c + 1, 1);
        }
    }

    void solve() {
        set<string> S;
        string p = "a";
        cout << "?" << p << endl;
        S.insert(p);
        while (true) {
            string s; cin >> s;
            if (S.count(s)) {
                cout << "!OUT" << endl;
                return;
            }
            if (s[0] != p[p.size() - 1]) {
                cout << "!OUT" << endl;
                return;
            }
            S.insert(s);
            string a = s.substr(0, 1);
            string b = s.substr(s.size() - 1, 1);
            if (not S.count(b + "a")) {
                cout << "?" << b + "a" << endl;
                S.insert(b + "a");
                p = b + "a";
            } else {
                string t = "";
                for (; S.count(b + t + "a"); t = succ(t)) ;
                t = b + t + "a";
                cout << "?" << t << endl;
                S.insert(t);
                p = t;
            }
        }
    }
}

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

Measured memory_bytes: 3236
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
typedef long long ll;

ll zbr,n,k;

int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

cin >> n >> k;

while (n>0){
	n/=k;
	zbr++;
}

cout << zbr;


return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int lli;
typedef vector<vector<lli> > vlli;
lli N, K;
lli MOD = 1e9 +7;
lli dfs(vector<int> &A, lli i, int N, vector<lli> &M){
	if(i>=N) return INT_MAX;
	if(i==N-1) return 0;
	if(M[i]!=-1) return M[i];
	lli ans = 1e10;
	for (int k = 1; k <= K; ++k)
	{
		ans = min(ans, dfs(A, i+k, N, M)+abs(A[i+k]-A[i]));
	}
	// lli x = dfs(A, i+1, N, M);
	// lli y = dfs(A, i+2, N, M);
	// if(x==INT_MAX and y==INT_MAX)
	// 	return M[i]=INT_MAX;
	// if(x!=INT_MAX and y!=INT_MAX)
	// 	return M[i]=min(x+abs(A[i+1]-A[i]), y+abs(A[i+2]-A[i]));
	// if(x!=INT_MAX and y==INT_MAX)
	// 	return M[i]=(x+abs(A[i+1]-A[i]));
	// if(x==INT_MAX and y!=INT_MAX)
		// return M[i]=(y+abs(A[i+2]-A[i]));
	return M[i]=ans;
}
int main() 
{ 
    cin>>N>>K;
    vector<int> A(N+K+K+5, 0);
    vector<lli> M(N+K+K+5, -1);
    
    for (int i = 0; i < N; ++i)
    {
    	cin>>A[i];
    }
    cout<<dfs(A, 0, N, M);
    return 0; 
}

Measured memory_bytes: 10752
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    string S;
    bool F=false;

int main(){
    cin>>S;
    REP(i,S.size()-1){
        if(S.substr(i,2)=="AC"){F=true;break;}
    }
    cout<<(F?"Yes":"No");
    return 0;

}


Measured memory_bytes: 256
def divisor(n):
    i=1
    table=[]
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            table.append(i)
            if i != n//i:
                table.append(n//i)
    return table

n = int(input())
res = 0
for i in range(1, n+1, 2):
    if len(divisor(i))==8:
        res += 1
print(res)

Measured memory_bytes: 3064
n = int(input())
s = input()
replace_list = []
a_ascii = ord("A")
for i in s:
    i_ascii = ord(i) + n
    x = i_ascii - a_ascii
    if x > 25:
        y = x - 26
        replace_i = chr(a_ascii + y)
        replace_list.append(replace_i)
    else:
        replace_i = chr(i_ascii)
        replace_list.append(replace_i)
print("".join(replace_list))

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

int main() {
   string S;
   cin >> S;
   int count=0;
   int n= S.size();
   for(int i=0; i<n/2; i++) {
      if(S[i] != S[n-1-i]) count++;
   }
   cout << count << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

import static java.lang.System.in;

public class Main {
    final static long MOD = (int) (10E8 +7);
    public static void main(String[] args) {
        Scanner scanner = new Scanner(in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        if(k==0) {
            System.out.println(1);
            return;
        }
        long[][] dp = new long[n+1][k+1]; // children and  candies
        for(int child =0;child<=n;child++){
            for (int candy = 0; candy <= k; candy++) {
                if(candy==0 || child==0){
                    dp[child][candy]=1;
                }
                else {
                    int R = candy;
                    int L = candy - Math.min(candy, arr[child - 1]) - 1;
                    if (L == -1)
                        dp[child][candy] = (dp[child][candy]% MOD +dp[child - 1][R]% MOD) % MOD;
                    else
                        dp[child][candy] = (dp[child][candy]% MOD +dp[child - 1][R]% MOD - dp[child - 1][L]%MOD + MOD) % MOD;
                    dp[child][candy] = (dp[child][candy]% MOD+dp[child][candy - 1]% MOD) % MOD;
                }
            }
        }
        System.out.println((dp[n][k]% MOD-dp[n][k-1]% MOD + MOD)% MOD);
    }
}

Measured memory_bytes: 140792
n = int(input())
result=1
a = list(map(int,input().split()))
    
if 0 in a:
    print(0) 
else:
    for i in a:
        result*=i
        if result > 10**18:
            print(-1)
            break
    if result <= 10**18:
        print(result)
        

Measured memory_bytes: 21624
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) {
        cin >> h[i];
    }
    if (n==1) {
        cout << "Yes" << "\n";
        return 0;
    }
    bool j = true;
    rep(i,n-1) {
        if (h[i]-h[i-1]>0) {
            h[i]--;
        }
    }
    for(int i=0; i<n-1; ++i) {
        if (h[i]>h[i+1]) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
}

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

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int32_t main() {
	int n, m;
	cin >> n >> m;
	vi h(n);
	for(int i = 0; i < n; i++)
		cin >> h[i];
	vvi to(n);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		to[a].pb(b);
		to[b].pb(a);
	}
	int res = 0;
	for(int i = 0; i < n; i++) {
		bool ok = 1;
		for(int j : to[i])
			ok &= (h[i] > h[j]);
		res += ok;
	}
	cout << res << '\n';
}


Measured memory_bytes: 9812
#include <iostream>

using namespace std;

const int kMaxN = 10;

int main () {
    string s;
    cin >> s;

    char c[kMaxN];

    int index = 0;

    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '0') {
            c[index] = '0';
            ++index;
        }
        else if (s[i] == '1') {
            c[index] = '1';
            ++index;
        }
        else if (s[i] == 'B') {
            if (index != 0) {
                --index;
            }
        }
    }

    for (int i = 0; i < index; ++i) {
        cout << c[i];
    }

    cout << endl;
}


Measured memory_bytes: 256
N = int(input())
coin = []
index = 0
cash = 0
man = 1
answer = 0.0
while(N > 0):
    j = [i for i in input().split()]
    coin.append(j)
    coin[index][cash] = float(coin[index][cash])
    index += 1
    N -= 1
index -= 1
while(index >= 0):
    if(coin[index][man] == "JPY"):
        answer += float(coin[index][cash])
    else:
        answer += float(coin[index][cash]) * 380000.0
    index -= 1
print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int ret=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return w*ret;
}
int n,k;
int r,s,p;
char ch[100010];
int a[100010];
int f[100010];
int ans=0;
inline int cal(int i)
{
	if(a[i]==1) return r;
	else if(a[i]==2) return s;
	else return p;
}
int main()
{
	scanf("%d %d",&n,&k);
	scanf("%d%d%d",&r,&s,&p);
	scanf("%s",ch+1);
	for(int i=1;i<=n;i++)
	if(ch[i]=='r') a[i]=3;
	else if(ch[i]=='s') a[i]=1;
	else a[i]=2;
	for(int i=1;i<=n;i++)
	if(i-k<=0) f[i]=a[i],ans+=cal(i);
	else if(f[i-k]==a[i]) f[i]=0;
	else f[i]=a[i],ans+=cal(i);
	cout<<ans<<endl;
	return 0;
}


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

#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define rep(i,n) reps(i,0,n)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define X first
#define Y second
#define pb push_back

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

const ll INF = 1e9;

struct dice{
	int d[6];
	int point(){ return d[0]; }
	void set(int l, int r, int f, int b, int _d, int u){
		d[3] = l;
		d[1] = r;
		d[4] = f;
		d[5] = b;
		d[0] = _d;
		d[2] = u;
	}
};

void rot(dice &dc, pii &pos, char r){
	if( r == 'L' ){
		swap( dc.d[0], dc.d[3] );
		swap( dc.d[3], dc.d[2] );
		swap( dc.d[2], dc.d[1] );
		pos.X--;
	}else if( r == 'R' ){
		swap( dc.d[0], dc.d[1] );
		swap( dc.d[1], dc.d[2] );
		swap( dc.d[2], dc.d[3] );
		pos.X++;
	}else if( r == 'F' ){
		swap( dc.d[0], dc.d[4] );
		swap( dc.d[4], dc.d[2] );
		swap( dc.d[2], dc.d[5] );
		pos.Y--;
	}else if( r == 'B' ){
		swap( dc.d[0], dc.d[5] );
		swap( dc.d[5], dc.d[2] );
		swap( dc.d[2], dc.d[4] );
		pos.Y++;
	}
}

dice dice_org[20];
pii dice_pos[20];
string dice_rot[20];
map<pii,int> tb[20];
void rots(int n){
	dice dc = dice_org[n];
	pii pos = dice_pos[n];
	// pre
	tb[n][pii(pos.X, pos.Y)] = dc.point();
	for(auto c: dice_rot[n]){
		rot( dc, pos, c );
		tb[n][pii(pos.X,pos.Y)] = dc.point();
	}
}

int solve(map<pii,int> &table, int n, bool update=false){
	// merge
	int sum = 0;
	for(auto p: tb[n]) if( table.count(p.X) == 0 ){
		if(update) table[p.X] = p.Y;
		sum += p.Y;
	}
	return sum;
}

map<pii, int> tables[1<<20];
int main(){
	int N;
	while(cin >> N, N){
		rep(i,N){
			int x, y;
			cin >> x >> y;
			x += 2000;
			y += 2000;
			dice_pos[i].X = x;
			dice_pos[i].Y = y;

			int l, r, f, b, d, u; 
			cin >> l >> r >> f >> b >> d >> u; 
			dice_org[i].set(l, r, f, b, d, u);

			cin >> dice_rot[i];
		}

		rep(i,N){
			tb[i].clear();
			rots(i);
		}
		rep(i,1<<20) tables[i].clear();

		int dp[1<<20] = {};
		rep(i, 1<<N){
			auto table = tables[i];
			rep(k,N){
				int nx = (1<<k)|i;
				if( nx != i ){
					if( tables[nx].empty() ){
						dp[nx] = max( dp[nx], dp[i] + solve(table, k, true) );
						tables[nx] = table;
						table = tables[i];
					}else{
						dp[nx] = max( dp[nx], dp[i] + solve(table, k) );
					}
				}
			}
			tables[i].clear();
		}
		cout << dp[(1<<N)-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 220272
S = input()
N = len(S)
s, t = 0, 0
for i in range(N):
    if S[i] == "A":
        s = i
        break

for i in range(N - 1, -1, -1):
    if S[i] == "Z":
        t = i
        break

print(t - s + 1)

Measured memory_bytes: 3512
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m ] <- readInts
	as <- concat . map tail <$> replicateM n readInts
	print $ length $ filter ( == n ) $ map length $ group $ sort as

Measured memory_bytes: 1020
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];

    vector<int> x(M), y(M), c(M);
    rep(i, M) cin >> x[i] >> y[i] >> c[i];
    int mini_a = INF;
    int total = 0;
    rep(i, A){
        mini_a = min(mini_a, a[i]);
    }
    int mini_b = INF;
    rep(i, B){
        mini_b = min(mini_b, b[i]);
    }
    total = mini_a + mini_b;

    int set_mini = INF;
    rep(i, M){
        int price = a[x[i] - 1] + b[y[i] - 1] - c[i];
        set_mini = min(set_mini, price);
    }
    cout << min(total, set_mini) << endl;
    return 0;
}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 2176