akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    long H, W, D;
    {
        auto input = readln.chomp.split(' ').map!(to!long);
        H = input[0];
        W = input[1];
        D = input[2];
    }
    long[2][] table = new long[2][](H * W + 1);
    foreach (h; 0 .. H)
    {
        auto input = readln.chomp.split(' ').map!(to!long).array;
        foreach (w, n; input)
        {
            table[n] = [h, w];
        }
    }

    long[] cost = new long[](H * W + 1);
    foreach (i; D + 1 .. H * W + 1)
    {
        cost[i] = cost[i - D] + abs(table[i][0] - table[i - D][0]) + abs(
                table[i][1] - table[i - D][1]);
    }

    auto Q = readln.chomp.to!long;
    foreach (_; 0 .. Q)
    {
        long L, R;
        {
            auto input = readln.chomp.split(' ').map!(to!long);
            L = input[0];
            R = input[1];
        }
        writeln(cost[R] - cost[L]);
    }
}


Measured memory_bytes: 5628
s = input()
k = int(input())
l = "abcdefghijklmnopqrstuvwxyz"
d = {}

for i in range(26):
    cnt = s.count(l[i])
    pre = 0
    if cnt > 0:
        for j in range(cnt):
            pos = s.find(l[i], pre)
            pre = pos + 1
            for m in range(min(len(s) - pos, k)):
                if s[pos:pos + m + 1] not in d:
                    d[s[pos:pos + m + 1]] = 1
    if len(d) >= k:
        dl = []
        for i in d.keys():
            dl.append(i)
        dl.sort()
        print(dl[k - 1])
        exit()

Measured memory_bytes: 9148
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;



int main(){
    // int u, v;
    // bool updated = false;
    ll N, M, cost, total_num;
    scanf("%lld", &N);
    total_num = 0;
    for(ll i=1;i<=N;i++){
        if(i % 3 != 0 && i % 5 != 0){
            total_num += i;
        }
    }

    printf("%lld\n", total_num);


    return 0;

}

Measured memory_bytes: 3228
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int n;
	cin >> n;
	BitRep(i, n) {
		bitset<18> bit(i);
		cout << i << ":";
		Rep(j, n) {
			if (bit[j]) cout << " " << j;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
/// Thank you tanakh!!!
///  https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(s: chars);

    let n = s.len();
    let mut ans = 0;
    for i in 1..n {
        for j in (i + 1)..n {
            for k in (j + 1)..n {
                let s1: String = s[0..i].iter().map(|&c| c).collect();
                let s2: String = s[i..j].iter().map(|&c| c).collect();
                let s3: String = s[j..k].iter().map(|&c| c).collect();
                let s4: String = s[k..].iter().map(|&c| c).collect();
                assert!(s1.len() > 0);
                assert!(s2.len() > 0);
                assert!(s3.len() > 0);
                assert!(s4.len() > 0);

                let t1 = s1.parse::<usize>().unwrap();
                let t2 = s2.parse::<usize>().unwrap();
                let t3 = s3.parse::<usize>().unwrap();
                let t4 = s4.parse::<usize>().unwrap();
                if t1 > 255 || t2 > 255 || t3 > 255 || t4 > 255 {
                    continue;
                }

                let t1 = t1.to_string();
                let t2 = t2.to_string();
                let t3 = t3.to_string();
                let t4 = t4.to_string();
                if t1.len() != s1.len()
                    || t2.len() != s2.len()
                    || t3.len() != s3.len()
                    || t4.len() != s4.len()
                {
                    continue;
                }
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 5032
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  
  int H, W, i, j, k;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
  queue<P> nxs;
  
  int cnt_sn = 0; //シャープの数
  int cnt_fn = 0; //フェイズ内の要素の数
  int cnt    = 0; // フェイズの数
  for(i = 0; i < H; i++){
    for(j = 0; j < W; j++){
      cin >> A.at(i).at(j);
      if(A.at(i).at(j) == '#'){
        nxs.push(P(i, j));
        cnt_sn++;
      }
    }
  }
  
  while(nxs.size() != 0 && cnt_sn < W * H){
     
    if(cnt_fn == 0){
      cnt++; cnt_fn = nxs.size();
    }
    P pos = nxs.front(); nxs.pop();
    for(i = 0; i < 4; i++){
      int x = pos.second + dx.at(i), y = pos.first + dy.at(i);
      if(x >= 0 && y >= 0 && x < W && y < H){
        if(A.at(y).at(x) == '.'){
          A.at(y).at(x) = '#';
          cnt_sn++;
          nxs.push(P(y, x));
        }
      }
    }
    cnt_fn--;
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 12464
import java.util.ArrayList;
import java.util.Scanner;

class Dice4{
	private int[] number = new int[6]; //Diceの方向には何の数字かを示す
										//初期値の順番と一緒：上面①、その下②、その右③、その左④、その上⑤、その反面⑥（Indexと一個違い）

	public Dice4(int[] n) {
		for (int i=0; i< 6; i++)number[i] = n[i];
	}

	public int getDice(int no) {
		return number[no];
	}

	public void roll(String target) {
		int [] w = new int[6];  //仮のway
		int a = target.length();
		for (int i=0; i<a; i++) {
			for (int j=0; j< 6; j++) w[j] = number[j];  //コピーする
			String t = target.substring(i, i+1);
			switch(t) {
			case "N":
				number[4] = w[0];
				number[0] = w[1];
				number[1] = w[5];
				number[5] = w[4];
				break;
			case "E":
				number[2] = w[0];
				number[0] = w[3];
				number[3] = w[5];
				number[5] = w[2];
				break;
			case "S":
				number[4] = w[5];
				number[0] = w[4];
				number[1] = w[0];
				number[5] = w[1];
				break;
			case "W":
				number[2] = w[5];
				number[0] = w[2];
				number[3] = w[0];
				number[5] = w[3];
				break;
			}
		}
	}

	public void rollToAB(int A,int B) {
		if (number[0]!=A) {		//Aは①面ではない
			if (number[2] == A) roll("W"); //Aが③の時：W
			else if (number[3] == A) roll("E"); //Aが④の時：E
			else if (number[1] == A) roll("N"); //Aが②の時：N
			else if (number[4] == A) roll("S"); //Aが⑤の時：S
			else roll("NN"); //Aが⑥の時：NN
		}
		if (number[1]!=B){  //Aは①面にあって、Bは②にない
			if (number[2] == B) roll("WSE");  //Bが③の時：W→S→E
			else if (number[3] == B) roll("ESW");  //Bが④の時：E→S→W
			else if (number[4] == B) roll("SENWSE");  //Bが⑤の時：S→E→N→Bが③になる→W→S→E
			else number[2] = -1;  //Bが⑥の時：必ず異なる
		}
	}
}

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			int nod = sc.nextInt();  //number of dice

			Dice4[] dices = new Dice4[nod];  //Diceの配列を生成

			int [] n = new int[6];
			for (int i=0; i<nod; i++) {
				for (int j=0; j<6; j++) {
					n[j] = sc.nextInt();
				}
				dices[i] = new Dice4(n);  //初期化
			}

			boolean flag = false;
			ArrayList<Integer> array = new ArrayList<Integer>();

			//ラベルで二重ループを脱出
			comparison: for (int i=0; i<nod-1; i++) {  //サイコロの数-1でループ
				for (int j=i+1; j<nod; j++) {  //dice iとその以降のサイコロを比較
					array.removeAll(array);  //初期化
					for (int k=0; k<6; k++) array.add(dices[i].getDice(k));  //dice iの面をArrayListに入れる
					for (int k=0; k<6; k++) {
						int side = dices[j].getDice(k);  //チェックする面を取得
						if (array.contains(side)) array.remove(array.indexOf(side));  //同じのあったら消す
					}
					if (array.size() == 0) {  //6面の数字が一緒だったら（全部消したら）
						dices[j].rollToAB(dices[i].getDice(0), dices[i].getDice(1));  //dice jの向きを調整する
						if ((dices[i].getDice(2) == dices[j].getDice(2)) && (dices[i].getDice(3) == dices[j].getDice(3)) &&
								(dices[i].getDice(4) == dices[j].getDice(4)) && (dices[i].getDice(5) == dices[j].getDice(5))) {
							flag = true; //同じサイコロがあったらtrue
							break comparison; //以降の検証いらない
						}
					}
				}
			}
			System.out.println(flag ? "No" : "Yes");
		}
	}
}


Measured memory_bytes: 29480
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (x == 0 && y == 0)
				break;
			else
				opi(x, y);
			System.out.println();
		}
		sc.close();
	}

	static void opi(int x, int y) {
		for (int i = 0; i < x; i++) {
			for (int j = 0; j < y; j++) {
				System.out.print("#");
			}
			System.out.println();
		}
	}
}



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

int cmp(const void *a,const void *b){
  return *(int *)a - *(int *)b;
}

int main(void){
  int t[3] = {0,0,0},
      l,i,j;
  scanf("%d\n",&l);
  for(i = 0;i < l;i++){
    scanf("%d %d %d\n",&t[0],&t[1],&t[2]);
    qsort(t,3,sizeof(int),cmp);
    if(t[0]*t[0]+t[1]*t[1]==t[2]*t[2])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)

int N;
int t[16][17], dp[1 << 16];
int dfs(int S){
    if(dp[S] != -1) return dp[S];
    if(S == (1 << N) - 1)return dp[S] = 0;
    int res = INF;
    rep(i, N){
        if((S >> i) & 1) continue;
        int p = t[i][0];
        rep(j, N)
          if((S >> j) & 1)
            p = min(p, t[i][j + 1]);
        res = min(res, dfs(S | 1 << i) + p);
    }
    return dp[S] = res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N && N){
        rep(i, N) rep(j, N + 1) cin >> t[i][j];
        memset(dp, -1, sizeof(dp));
        cout << dfs(0) << endl;
    }
    return 0;
}

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

string S,T;

int main()
{
    cin >> S >> T;
    sort(S.begin(),S.end());
    sort(T.begin(),T.end());
    reverse(T.begin(),T.end());
    if(S < T)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int a; 
    scanf("%d", &a);
    printf("%d", a/3);
    
}


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

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

    int count = 0;

    for(int i=1; i<n; i++){
        if(s[i] == 'E'){
            count++;
        }
    }

    int ans = count;

    for(int i=0; i<n-1; i++){
        string t = s.substr(i,2);
        if(t == "WW"){
            count++;
        }else if(t == "EE"){
            count--;
        }
        if(count < ans){
            ans = count;
        }
    }

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

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    ll d,t,s;cin>>d>>t>>s;
    if(d<=t*s){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0184
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int[] Cnt = new int[7];
                for (int i = 0 ; i < n ; i++)
                {
                    int ageClass = (RInt() / 10);
                    if (ageClass <= 5) Cnt[ageClass]++; else Cnt[6]++;
                }

                for (int i = 0 ; i < Cnt.Length ; i++)
                {
                    Console.WriteLine(Cnt[i]);
                }
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 20080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> a(55),b(55),c(55),d(55);
  for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
  for(int i=0;i<M;i++){cin >> c[i] >> d[i];}
  int m,num;
  for(int i=0;i<N;i++){
    m=300000000;
    for(int j=0;j<M;j++){
      if(m>abs(a[i]-c[j])+abs(b[i]-d[j])){
        m=abs(a[i]-c[j])+abs(b[i]-d[j]);
        num=j+1;
      }
    }
    cout << num << endl;
  }
}

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

const int N=1005;
const int MOD=1e9+7;
 
 
int32_t main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
*/
  int a,b;
  cin>>a>>b;
  int z=0;
  int c=min(a,b);
  for(int i=c;i<=100000;i++)
  {
    int x=i*0.08;
    int y=i*0.1;
    if(x==a && y==b)
    {
      z=i;
      break;
    }
  

    
  }
  if(z==0)
  {
    cout<<"-1";

  }
  else
  {
    cout<<z;
  }

    
}


Measured memory_bytes: 256
from collections import deque
def main():
    s = deque(raw_input().strip())
    ans = 0
    while len(s) > 1:
        st = s[0]
        nd = s[-1]
        if st == nd:
            s.pop()
            s.popleft()
        elif st == 'x':
            s.popleft()
            ans += 1
        elif nd == 'x':
            s.pop()
            ans += 1
        else:
            print -1
            return
    print ans
main()


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

const int WIDTH = 112345;

void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v){
    int i, i1;
    auto table = vector<vector<ll>>(2, vector<ll>(WIDTH, W+1)); //min weight
    table[N%2][0] = 0;
    for(int i_=N-1; i_ >= 0; i_--){
        i = i_%2;
        i1 = (i_+1)%2;
        for(int j=0; j < WIDTH; j++){
            ll nouse = table[i1][j];
            if(j - v[i_] >= 0){
                ll used = table[i1][j - v[i_]] + w[i_];
                table[i][j] = min(used, nouse);
            }else{
                table[i][j] = nouse;
            }
        }
    }

    for(int j=WIDTH-1; j >= 0; j--){
        if(table[i][j] < W+1){
            cout << j << endl;
            break;
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> w(N);
    std::vector<long long> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&w[i]);
        scanf("%lld",&v[i]);
    }
    solve(N, W, std::move(w), std::move(v));
    return 0;
}


Measured memory_bytes: 3452
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

long long inputValueLongLong(){
    long long a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int Kaijou(int N){
    if(N>1){
        return Kaijou(N-1)*N;
    }else{
        return 1;
    }
}

int main(int argc, const char * argv[]) {
    // source code
    int N = inputValue();
    int x[N],y[N];
    int i=0;
    int j=0;
    double distance[N][N];
    double distSum=0;
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            distance[i][j] = 0;
        }
    }
    for(i=0;i<N;i++){
        x[i] = inputValue();
        y[i] = inputValue();
        for(j=i-1;j>=0;j--){
            distance[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
            distance[j][i] = distance[i][j];
            distSum += distance[i][j]*Kaijou(N-1)*2;
        }
    }


    double res = distSum/Kaijou(N);
    printf("%.10lf\n",res);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int N;
	cin >> N;
	vector<int>a(N);
	int sum = 0;
	rep(i, N) {
		cin >> a[i];
		sum += a[i];
	}
	int ave1 = sum / N;
	int ave2 = ave1 + 1;
	int ans1 = 0, ans2 = 0;
	rep(i, N) {
		ans1 += pow(a[i] - ave1, 2);
		ans2 += pow(a[i] - ave2, 2);
	}
	int ans = min(ans1, ans2);
	cout << ans;
}

Measured memory_bytes: 256
let log2 b = (log10 b) /. (log10 2.)

let () =
  let n, k = Scanf.scanf "%d %d\n" (fun n k -> n, k) in
  let sum = ref 0. in
  for i = 1 to n do
    let n, k = float_of_int n, float_of_int k in
    let i' = float_of_int i in
    let cnt = let v = log2 (k /. i') in if v < 0. then 0. else v in
    let cnt = ceil cnt in
    let p = (0.5 ** cnt) /. n in
    sum := !sum +. p
  done;
  !sum |> print_float


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

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  vector<int>A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  
  int ans=X;
  
  for(int i=0; i<N; i++){
    ans += (D-1)/A.at(i)+1;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<math.h>

int main()
{
    int H =0;
    int W =0 ;
    int N =0 ;
    double NperH=0 ;
    double NperW=0 ; 
    int result =1;
   
    scanf ("%d", &H);
    scanf ("%d", &W);
    scanf ("%d", &N);
    
    NperH= ceil(N/(double)H);
    NperW= ceil(N/(double)W);
   // printf("%.2f",ceil(NperW)); debug only
    if (NperH < NperW)
    {
        printf("%d",(int)NperH);
    }
    else
    {
        printf("%d",(int)NperW);
    }
    
    return 0;
}

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

int main(){
  int x,a,b;
  cin >>x >>a >>b;
  int m = min(abs(a-x), abs(b-x));
  if(m == abs(a-x)) cout << "A" << endl;
  else cout << "B" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string r, a;
  while(cin>>r>>a, r!="0"){
    int h=0, b=0;
    for(int i=0;i<4;++i){
      if(r[i] == a[i]){
        h++;
        r[i] = 'X'; a[i] = 'Y';
      }
    }
    for(int i=0;i<4;++i){
      for(int j=0;j<4;++j){
        if(r[i] == a[j]){
          b++;
          break;
        }
      }
    }
    cout<<h<<" "<<b<<endl;
  }
  return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef list<ll> listl;
typedef string str;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))

#define _rep(i, m)		for(ll i = 0, i_max = m; i < i_max; i++)
#define _erep(i, m)		for(ll i = 0, i_max = m; i <= i_max; i++)
#define _brep(i, b, m)	for(ll i = b, i_max = m; i < i_max; i++)
#define _ebrep(i, b, m)	for(ll i = b, i_max = m; i <= i_max; i++)
#define _rrep(i, m)		for(ll i = m; i >= 0; i--)
#define _rerep(i, b, e)	for(ll i = b; i >= e; i--)

#define rep(m)			_rep(i, m)
#define erep(m)			_erep(i, m)
#define brep(b, m)		_brep(i, b, m)
#define ebrep(b, m)		_ebrep(i, b, m)
#define rrep(m)			_rrep(i, m)
#define rerep(b, e)		_rerep(i, b, e)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void in(ll& I)
{
	cin >> I;
}

void in(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(listl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(str& s)
{
	cin >> s;
}

void out(ll O)
{
	cout << O;
}

void out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

void rout(bool b, str True, str False)
{
	if (b)
	{
		cout << True.c_str();
	}
	else
	{
		cout << False.c_str();
	}
}

int main()
{
	ll N;
	in(N);
	ll A, B;
	in(A);
	in(B);

	out((N*A > B ? B : N * A));
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

struct Combination {
    vector<ll> fac, finv, inv;

    Combination(ll maxN) {
        maxN += 100; // for safety
        fac.resize(maxN + 1);
        finv.resize(maxN + 1);
        inv.resize(maxN + 1);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (ll i = 2; i <= maxN; ++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;
        }
    }
    ll operator()(ll n, ll k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main() {
    int n, p;
    cin >> n >> p;
    vi a(n);
    vi b(2, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[a[i] % 2]++;
    }
    ll ret = 0;
    Combination comb(100);
    if (p == 0) {
        ret = 1;
        for (int i = 2; i <= b[1]; i += 2) {
            ret += comb(b[1], i);
        }
    } else {
        for (int i = 1; i <= b[1]; i += 2) {
            ret += comb(b[1], i);
        }
    }
    for (int i = 0; i < b[0]; ++i) {
        ret <<= 1;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E [][] = new int [V+1][V+1];
		for (int i=1; i<=V; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			for (int k=0; k<b; k++){
				int c = sc.nextInt();
				E [a][c] = 1;
			}
		}
		Queue <Integer> Q = new ArrayDeque <Integer>();
		Q.add(1);
		int D [] = new int [V+1];
		D [1] = 1;
		while (Q.size()>0){
			int cur = Q.poll();
			for (int dst=1; dst<=V; dst++){
				if (E[cur][dst]==1 & D[dst]==0){
					D[dst]=D[cur]+1;
					Q.add(dst);
				}			
			}			
		}
		for (int m=1; m<=V; m++){
			System.out.println(m+" "+(D[m]-1));
		}
	}
}

Measured memory_bytes: 28044
N = int(input())
a = list(map(int, input().split()))
ans = 10000000000
total = sum(a)
sunuke = 0
for i in range(N-1):
    sunuke += a[i]
    dif = abs(2 * sunuke - total)
    if dif <= ans:
        ans = dif
print(ans)


Measured memory_bytes: 24824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

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

Measured memory_bytes: 3596
import math
n, d =list(map(int, input().split()))
data = []
count = 0
sum = 0
for i in range(n):
    data.append(list(map(int, input().split())))
for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (data[i][k] - data[j][k]) * (data[i][k] - data[j][k])
        if math.sqrt(sum).is_integer():
            count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;


int main(int argc, char **argv) {
    int n;
    cin >> n;
    int ans{0};
    std::vector<int> a(n, 0), b(n, 0), c(n, 0);
    for (int i=0; i<n; ++i) {
        cin >> a[i];
    }
    for (int i=0; i<n; ++i) {
        cin >> b[i];
    }
    for (int i=0; i<n-1; ++i) {
        cin >> c[i];
    }
    for (int i=0; i<n; ++i) {
        ans += b[a[i]-1];
        if (i != n-1) {
            if (a[i+1]-a[i] == 1) {
                ans += c[a[i]-1];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  rep(i,0,N) cin>>a[i];
  int count=0;
  int max=0;
  rep(i,0,N-1){
    if(a[i]>=a[i+1]){
      count++;
    }else{
      if(count>max){
        max=count;
      }
      count=0;
    }
  }
  if(count>max){
    max=count;
  }
  cout<<max;
    
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 640
#include<iostream>
#include<ctype.h>
using namespace std;
#define rep(i,s,n)for(int i=s;i<n;i++)
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  getline(cin, s);
  for (char &c:s){
    c=toupper(c);
  }
  cout << s << endl;
  return 0;
}


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

using namespace std;

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

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, d = 0; cin >> n;
	rep(i, n){
		int a; cin >> a;
		if(a != i + 1) d++;
	}
	cout << (d <= 2 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
a = input()
b = input()
mn = len(b)
for i in range((len(a) - len(b)) + 1):
    c = a[i:i+len(b)]
    count = 0
    for j in range(len(b)):
        if c[j] != b[j]:
            count += 1
    if mn > count:
        mn = count
print(mn)

Measured memory_bytes: 9032
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int a; cin >> a;
    int s = a / 1000;
    int h = a % 1000 / 100;
    int j = a % 100 / 10;
    int i = a % 10;

    cout << (h == j && ((h == s) || (j == i)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
 
int main(){
  int ex = 0;
  string S, T;
  
  cin >> S >> T;
  
  for(int i = 0; i < 3; i++){
    if(S[i] == T[i]) ex++;
  }
  
  cout << ex << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n, t, a, x1, y1, x2, y2, res1 = 1, res2 = 1;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> t >> a;
        x1 = (res1 % t == 0 ? res1 : (res1 / t + 1) * t);
        y1 = x1 / t * a;
        y2 = (res2 % a == 0 ? res2 : (res2 / a + 1) * a);
        x2 = y2 / a * t;
        if (y1 < res2) {
            res1 = x2, res2 = y2;
        } else if (x2 < res1) {
            res1 = x1, res2 = y1;
        } else {
            res1 = min(x1, x2), res2 = min(y1, y2);
        }
    }
    cout << res1 + res2 << endl;
}


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

#define fi              first
#define se              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll              vector<int>
#define mll             map<ll,ll>
#define pqg             priority_queue<ll>
#define pqs             priority_queue<ll,vll,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define md             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x

void hi()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
}

void subsetsUtil(vector<int>& A, vector<vector<int> >& res, 
                 vector<int>& subset, int index) 
{ 
    res.push_back(subset); 
    for (int i = index; i < A.size(); i++) { 
  
        // include the A[i] in subset. 
        subset.push_back(A[i]); 
  
        // move onto the next element. 
        subsetsUtil(A, res, subset, i + 1); 
  
        // exclude the A[i] from subset and triggers 
        // backtracking. 
        subset.pop_back(); 
    } 
  
    return; 
} 
  
// below function returns the subsets of vector A. 
vector<vector<int> > subsets(vector<int>& A) 
{ 
    vector<int> subset; 
    vector<vector<int> > res; 
  
    // keeps track of current element in vector A; 
    int index = 0; 
    subsetsUtil(A, res, subset, index); 
  
    return res; 
} 
int main()
{
    //hi();
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n,m,x;
    cin>>n>>m>>x;
    ll c[n][m],co[n];
    for(int i=0;i<n;i++)
    {
        cin>>co[i];
        for(int j=0;j<m;j++) cin>>c[i][j];
    }
    vector<int> array;
    for(int i=0;i<n;i++) array.pb(i);
    ll ans=inf,v[m]={0}; 
    vector<vector<int> > res = subsets(array); 
    for (int i = 0; i < res.size(); i++) {
        ll val=0;
        for (int j = 0; j < res[i].size(); j++) 
            {
                for(ll k=0;k<m;k++)
                v[k]+=c[res[i][j]][k];
                //cout << res[i][j] << " ";
                val+=co[res[i][j]];
            } 
            bool ch=true;
        for(ll i1=0;i1<m;i1++)
            {
                if(v[i1]<x) ch=false;
                v[i1]=0;
            }
            if(ch) ans=min(ans,val);
        //cout << endl; 
    }
    ans==inf?cout<<"-1\n":cout<<ans<<"\n"; 
    return 0;
}

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

using namespace std;

typedef long long ll;

template<class T>
inline T gcd(T a, T b) {
  return b > 0 ? gcd(b, a % b) : a;
}

template<class T>
inline T lcm(T a, T b) {
  return a*b/gcd(a, b);
}

int main() {
  int N;
  
  while(cin >> N && N) {
    vector<ll> d(N), v(N);
    
    for(int i=0; i<N; i++) {
      cin >> d[i] >> v[i];
      int const GCD = gcd(d[i], v[i]);
      d[i] /= GCD, v[i] /= GCD;
    }
    
    ll D = d[0], V = v[0];
    for(int i=1; i<N; i++) {
      D = lcm(D, d[i]);
      V = gcd(V, v[i]);
    }
    
    for(int i=0; i<N; i++) {
      cout << (v[i] * D) / (d[i] * V) << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1196
N = int(input())
A = list(map(int, input().split()))
 
s, t = 0, 0
for i in range(N):
  s += A[i]
  t += A[i]**2
s = s**2

ans = (s-t) % (10**9+7)
# tmp = (2**1000000005) % (10**9+7)
tmp = 500000004
ans = (ans*tmp) % (10**9+7)
print(ans)

Measured memory_bytes: 31644
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

int main(){
    int N, M;
    string s, t;
    cin >> N;
    map<string, int> d{};
    for (int i=0; i<N; ++i){
        cin >> s;
        if ( d.find(s) == d.end() ) {          
            d[s] = 1;
        }
        else {
            d[s] += 1;
        }
    }
    cin >> M;
    for (int i=0; i<M; ++i){
        cin >> t;
        if ( d.find(t) == d.end() ) {       
            d[t] = -1;
        }
        else {
            d[t] -= 1;
        }
    }
    string maxkey;
    int maxv = -999;
    string key;
    int value;
    for (auto iter = d.begin(); iter != d.end(); iter++) {
        // first: key, second: value

        key = iter->first;
        value = iter->second;
        if (value > maxv){
            maxkey = key;
            maxv = value;
        }
    }
    if (maxv < 0) maxv = 0;
    cout << maxv << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
int main(void){
  long int x;
  long double a=100.0;
  long int i=0;
  scanf("%ld", &x);
  while(a<x){
    a = floorl(1.01*a);
    i++;
  }
  printf("%ld", i);
  return 0;
}
    


Measured memory_bytes: 1736
#include <bits/stdc++.h>
 
using namespace std;
int n;
 
long long valor[105];
long long peso [105];
long long dp [105][106000];
int p;
 
long long pd(long long id, long long aguenta)
{
    if (dp[id][aguenta]!=-1){return dp[id][aguenta];}
    if (id==n or !aguenta) {return dp[id][aguenta]=0;}
 
    long long nao_pega=pd(id+1,aguenta);
 
    if(peso[id]<=aguenta){
       long long pega=valor[id]+pd(id+1, aguenta - peso[id]);
        return dp[id][aguenta]=max(pega,nao_pega);
    }
 
 
return dp[id][aguenta]=nao_pega;
 
}
 
 
 
 
 
int main ()
{
    cin>>n;
    cin>>p;
for (int i=0;i<n;i++){
    cin>>peso[i];
    cin>>valor[i];
 
 
}
memset(dp,-1,sizeof(dp));
cout<<pd(0,p);
 
 
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    while(S != "#"){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;b--;c--;d--;
        vector<string> G(15);
        int now = 0;
        for(int i=0; i<S.size(); i++){
            if(S[i] == '/'){
                now++;
            }else{
                if(S[i] == 'b'){
                    G[now].push_back('b');
                }else{
                    int cnt = S[i]-'0';
                    while(cnt){
                        G[now].push_back('.');
                        cnt--;
                    }
                }
            }
        }
        now++;
        swap(G[a][b],G[c][d]);
        string ans = "";
        for(int i=0; i<now; i++){
            int cnt = 0;
            for(int j=0; j<G[i].size(); j++){
                if(G[i][j] == '.'){
                    cnt++;
                }else{
                    if(cnt){
                        ans.push_back(cnt+'0');
                    }
                    cnt = 0;
                    ans.push_back('b');
                }
            }
            if(cnt){
                ans.push_back(cnt+'0');
                cnt = 0;
            }
            if(i != now-1){
                ans.push_back('/');
            }
        }
        cout << ans << "\n";
        cin >> S;
    }
    return 0;
}



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

int main() {
  int N,A;
  int fx = 0;
  cin >> N;
  A = N;
  for(int i;i < 9;i++){
    fx += N % 10;
    N = (N - N % 10) / 10; 
  }
  if (A % fx == 0){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

const ll L = 1e5+5;

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

    ll N, M;
    cin >> N >> M;

    string S;
    cin >> S;

    vector <ll> ans;
    ll upto = N-1;

    for(ll i=N; i>=0; i--)
    {
        ll pos = -1;

        for(ll j=max(0LL, i-M); j<=upto; j++)
        {
            if(S[j] == '0')
            {
                pos = j;
                break;
            }
        }

        // cout << upto << " " << pos << endl;

        if(pos == -1)
        {
            cout << -1 << endl;
            return 0;
        }

        ans.pb(i-pos);

        if(pos == 0)
        {
            break;
        }

        upto = i-M-1;
        i = pos+1;
    }

    reverse(all(ans));

    for(auto i: ans)
    {
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1480
#include<bits/stdc++.h>
using namespace std;
bool prime(int x)
{
    int y=sqrt(x);
    return y*y==x;
}
int main()
{
    int a,b;
    while(cin>>a>>b){
        if(a<b) swap(a,b);
        int flag=0;
        if(a<10&&b<10){
            if(prime(a+10*b)||prime(a*10+b)) flag=1;
        }
        else if(a>=10&&a<100&&b<10){
            if(prime(a+100*b)||prime(a*10+b)) flag=1;
        }
        else if(a>=10&&a<100&&b>=10&&b<100){
            if(prime(a+100*b)||prime(a+100*b)) flag=1;
        }
        else if(a==100&&b>=10&&b<100){
            if(prime(a+1000*b)||prime(a*100+b)) flag=1;
        }
        if(flag) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

const ll MAXN = 1e5 + 13;
vll P, Q;

int main(int argc, char **argv){
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll N, M, ans = 0, ca = 0;
    cin >> N >> M;

    P.assign(N, 0);
    Q.assign(N, -1);

    for(ll i = 0; i < M; ++i){
        ll id; string verdict;
        cin >> id >> verdict;

        if(verdict[0] == 'W'){
            P[id-1]++;
        }
        else{
            if(Q[id-1] == -1){ Q[id-1] = P[id-1]; ca++; }
        }
    }
    for(ll i = 0; i < N; ++i) if(Q[i] != -1) ans += Q[i];

    cout << ca << sp << ans << endl;

    return 0;
}

//cikisir



Measured memory_bytes: 1792
from fractions import gcd


A, B, C, D = map(int, input().split())

cc = B // C - (A - 1) // C
dd = B // D - (A - 1) // D
lcm = C * D // gcd(C, D)
cd = B // lcm - (A - 1) // lcm
ans = (B - A + 1) - cc - dd + cd
print(ans)


Measured memory_bytes: 5432
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (size_t i = 0; i < (size_t) (n); i++)

using namespace std;
using ll = long long;

int main(void) {
  int n, m, x;
  cin >> n >> m >> x;
  auto cs = vector<ll>(n);
  auto as = vector<vector<ll>>(n, vector<ll>(m));
  REP(i, n) {
    cin >> cs[i];
    REP(j, m) {
      cin >> as[i][j];
    }
  }

  ll ans = numeric_limits<ll>::max();
  for (int comb = 0; comb < (1 << n); comb++) {
    ll price = 0;
    auto ts = vector<ll>(m, x);
    REP(i, n) {
      if (comb & (1 << i)) {
        price += cs[i];
        REP(j, m) ts[j] -= as[i][j];
      }
    }

    bool ok = true;
    REP(i, m) {
      ok = ok && ts[i] <= 0;
    }
    if (ok) ans = min(ans, price);
  }
  cout << (ans == numeric_limits<ll>::max() ? -1 : ans) << endl;
}


Measured memory_bytes: 3636
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 80, M = 80, D = (N + M - 1) * 80;

int aa[N][M];
bool dp[N][M][D + 1];

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> aa[i][j];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			int a; cin >> a;
			aa[i][j] = abs(aa[i][j] - a);
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			int a = aa[i][j];
			if (i == 0 && j == 0) {
				dp[i][j][a] = true;
				continue;
			}
			if (i > 0)
				for (int b = 0; b <= D; b++)
					if (dp[i - 1][j][b]) {
						int c = a + b;
						if (c <= D)
							dp[i][j][c] = true;
						c = abs(a - b);
						dp[i][j][c] = true;
					}
			if (j > 0)
				for (int b = 0; b <= D; b++)
					if (dp[i][j - 1][b]) {
						int c = a + b;
						if (c <= D)
							dp[i][j][c] = true;
						c = abs(a - b);
						dp[i][j][c] = true;
					}
		}
	int c = 0;
	while (!dp[n - 1][m - 1][c])
		c++;
	cout << c << '\n';
	return 0;
}


Measured memory_bytes: 67208