akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

string S;
int N;
int solve(int now_keta,bool is_smaller,int now) {
    if (now_keta == S.size()) return now;
    if (is_smaller) return now + 9 * ((int)S.size() - now_keta);

    int see = S[now_keta];
    if ( see == '0') return solve(now_keta+1,is_smaller,now);

    int see_int = see - '0';
    // same
    int icchi = solve(now_keta+1,false,now+see_int);
    int bef = solve(now_keta+1,true,now+see_int-1);

    return max(icchi,bef);
}

int main() {
    cin >> S;
    N = S.size();
    cout << solve(0,false,0) << endl;
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

int R, C, Q;
char grid[2005][2005];
int sum[3][2005][2005];

int query(int id, int t, int l, int b, int r){
    if(t > b || l > r) return 0;
    return sum[id][b][r] - sum[id][t-1][r] - sum[id][b][l-1] + sum[id][t-1][l-1];
}

int main(){

    ios :: sync_with_stdio(false);
    cin >> R >> C >> Q;
    FOR(i,R){
        FOR(j,C){
            cin >> grid[i][j];
        }
    }

    FOR(i,R){
        FOR(j,C){
            sum[0][i][j] = sum[0][i-1][j] + sum[0][i][j-1] - sum[0][i-1][j-1] + (grid[i][j]=='1');
            sum[1][i][j] = sum[1][i-1][j] + sum[1][i][j-1] - sum[1][i-1][j-1] + (grid[i][j]=='1' && j<C && grid[i][j+1]=='1');
			sum[2][i][j] = sum[2][i-1][j] + sum[2][i][j-1] - sum[2][i-1][j-1] + (grid[i][j]=='1' && i<R && grid[i+1][j]=='1');
        }
    }

    FOR(q,Q){
        int t, l, b, r;
        cin >> t >> l >> b >> r;
        int ans = 0;
        ans += query(0, t, l, b, r);
        ans -= query(1, t, l, b, r-1);
        ans -= query(2, t, l, b-1, r);

        cout << ans << endl;
    }

    return 0;
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int main(){

    int n,m;
    cin >> n >> m;
    

    if(n <= 8 && m <= 8)cout <<"Yay!" ;
    else cout << ":(";
    
}


Measured memory_bytes: 256
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '4 2
  1
  2
  2
  6'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end



def check(n,k,arr,p)
  i = 0
  k.times do
    s=0
    while(s+arr[i]<=p)
      s+=arr[i]
      i += 1
      return n if(i==n)
    end
  end
  return i;
end

def solve(n,k,arr)
  left=0
  right=100000*10000
  while(right-left>1)
    mid = (left+right)/2
    v = check(n,k,arr,mid)
    if(v >= n)
      right=mid
    else
      left=mid
    end
  end
  return right
end

n,k = line[0].split(" ").map(&:to_i)

arr=[]
(1..n).each do |n|
  arr << line[n].to_i
end

ans = solve(n,k,arr)
puts ans

Measured memory_bytes: 14204
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<Pll>TS;
    for(ll i=0;i<n;i++){
        ll s,t;cin>>s>>t;
        TS.pb(mp(t,s));
    }
    sort(all(TS));
    ll ans=0,t=0;
    for(ll i=0;i<n;i++){
        if(t<TS[i].se){
            ans++;
            t=TS[i].fi;
        }
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------















































Measured memory_bytes: 4940
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	a, b := sc.nextInt(), sc.nextInt()
	c := b - a
	num := 0
	for i := c; i >= 1; i-- {
		num += i
	}

	fmt.Fprintln(wtr, num-b)
	wtr.Flush()
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	l1, l2 := read(), read()
	tmp := strings.Fields(l1)
	n, _ := strconv.Atoi(tmp[0])
	m, _ := strconv.Atoi(tmp[1])
	x, _ := strconv.Atoi(tmp[2])
	a := make(map[int]struct{}, m)
	for _, s := range strings.Fields(l2) {
		n, _ := strconv.Atoi(s)
		a[n] = struct{}{}
	}

	rcost := 0
	for i := x; i < n; i++ {
		if _, ok := a[i]; ok {
			rcost++
		}
	}

	lcost := 0
	for i := x; i >= 0; i-- {
		if lcost > rcost {
			break
		}
		if _, ok := a[i]; ok {
			lcost++
		}
	}

	if lcost > rcost {
		fmt.Println(rcost)
	} else {
		fmt.Println(lcost)
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=a;i<a*102;i+=a){
    if(i%b==c){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next()) + 1; //1-indexed
            boolean[] idx = new boolean[110000];
            Arrays.fill(idx, true);
            long ng = 0;
            for (int i = 1; i < n; i++) {
                if (Integer.parseInt(in.next()) == i) {
                    idx[i] = false;
                    ng++;
                }
            }
            long ans = 0;
            int i = 1;

            while (ng > 0 || i < n - 1) {
                if (!idx[i]) {
                    if (!idx[i + 1]) {
                        ng -= 2;
                        i += 2;
                    } else {
                        ng -= 1;
                        i += 1;
                    }
                    ans++;
                } else {
                    i += 1;
                }
            }


            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 57772
#include <stdio.h>

#define MAX 100
#define INFINITY 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, G[MAX][MAX];

void aoj() {
	int i, u, v, min, d[MAX], color[MAX];

	for (i = 0; i < n; i++) {
		d[i] = INFINITY;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;

	while (1) {
		min = INFINITY;
		u = -1;
		for (i = 0; i < n; i++) {
			if (min > d[i] && color[i] != BLACK) {
				u = i;
				min = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (v = 0; v < n; v++) {
			if (color[v] != BLACK && G[u][v] != INFINITY) {
				if (d[v] > d[u] + G[u][v]) {
					d[v] = d[u] + G[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (i = 0; i < n; i++) {
		printf("%d ",i);
		if (d[i] == INFINITY) printf("-1\n");
		else printf("%d\n",d[i]);
	}
}

int main() {
	int i, j,u,k,v,c;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			G[i][j] = INFINITY;
		}
	}

	for (i = 0; i < n; i++) {
		scanf("%d%d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d%d", &v, &c);
			G[u][v] = c;
		}
	}

	aoj();

	return 0;

}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;

const int N = 100006;


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll n, d;

    cin >> n >> d;
    d *= d;

    int ans = 0;

    for(int i = 1; i <= n; i++) {

        ll x, y;
        cin >> x >> y;

        ans += (x * x + y * y <= d);

    }   

    cout << ans << '\n';
    
    return 0; 
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

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

int main(){
	ll n;
	cin >> n;
	string s;
	vector<int> cnt(26, 0);
	rep(i, n){
		cin >> s;
		rep(j, 26){
			int temp_cnt = 0;
			rep(k, s.size()){
				if(s[k] == 'a' + j)temp_cnt += 1;
			}
			if(i != 0)cnt[j] = min(cnt[j], temp_cnt);
			else if(i == 0)cnt[j] = temp_cnt;
		}
	}
	rep(i,26){
		rep(j, cnt[i]){
			cout << char('a'+ i);
		}
	}
	cout << endl;
	
}

Measured memory_bytes: 256
#abc097b

x=int(raw_input())
r=[]
for i in xrange(1,32):
 for j in xrange(2,32):
  if i**j<=1000:
   r.append(i**j)
r2=[]
for i in xrange(len(r)):
 y=x-r[i]
 if y>=0:
  r2.append(r[i])
print max(r2)


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string s;
    cin >> s;
    ll ans;
    rep(i, 1, (ll)((s.size()+1)/2)){
        bool flag = true;
        rep(j, 0, i){
            if(s[j] != s[i+j]){
                flag = false;
                break;
            }
        }
        if(flag){
            ans = 2*i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

bool g[105][105];

int main() {
  int xx, yy;
  scanf("%d%d", &xx, &yy);
  int n;
  scanf("%d", &n);
  while(n--) {
    int x, y, a;
    scanf("%d%d%d", &x, &y, &a);
    if(a == 1) {
      for(int i = 0; i < xx; i++) {
        for(int j = 0; j < yy; j++) {
          if(i < x) g[i][j] = true;
        }
      }
    }
    if(a == 2) {
      for(int i = 0; i < xx; i++) {
        for(int j = 0; j < yy; j++) {
          if(i >= x) g[i][j] = true;
        }
      }
    }
    if(a == 3) {
      for(int i = 0; i < xx; i++) {
        for(int j = 0; j < yy; j++) {
          if(j < y) g[i][j] = true;
        }
      }
    }
    if(a == 4) {
      for(int i = 0; i < xx; i++) {
        for(int j = 0; j < yy; j++) {
          if(j >= y) g[i][j] = true;
        }
      }
    }
  }
  int ret = 0;
  for(int i = 0; i < xx; i++) {
    for(int j = 0; j < yy; j++) {
      if(!g[i][j]) {
        ret++;
      }
    }
  }
  printf("%d\n", ret);
}


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

bool isprime(int n){
	if(n < 2)return false;
	
	for(int i=2;i*i<=n;i++)
		if( n%i == 0)return false;
	return true;
}
int main(){
	int n;
	bool memo[1000000] = {false};
	for(int i=0;i<1000000;i++){
		memo[i] = isprime(i);
	}
	while(cin >> n){
		int output = 0;
		for(int i=0;i<=n;i++){
			if(memo[i])output++;
		}
		cout << output << endl;
	}
}

Measured memory_bytes: 2144
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        mut a: [i64;n],
    }
    let mut ok = true;
    let mut b = vec![0];
    b.append(&mut a.clone()); // 1-indexed
    let mut c = vec![-1;n+1]; // c_i
    let mut ans = vec![];
    for i in (1..n+1).rev() {
        let base = n/i;
        let mut sum = 0;
        let mut ind = i;
        loop {
            if ind + i > n {
                break;
            }
            sum+=c[ind+i];
            ind+=i;
            sum%=2;
        }
        // println!("{} {}",i,sum);
        c[i] = (b[i] - sum)%2;
        if c[i]<0 {
            c[i]+=2;
        }
        // println!("{:?}", b);
        // println!("{:?}", c);
        // println!("----");
        if c[i]==1 {
            ans.push(i);
        }
    }
    println!("{}", ans.len());
    for i in 0..ans.len() {
        if i == ans.len()-1 {
            println!("{}", ans[i]);
            break;
        }
        print!("{} ", ans[i]);
    }

}

Measured memory_bytes: 13180
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _012_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            long sum = 0;
            Array.Sort(array);
            for(int i = 0; i < n; i++)
            {
                sum +=array[n + i * 2];
            }
            Console.WriteLine(sum);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 42700
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    cnt=0
    while True:
        cnt+=1
        if n<=1000*cnt:
            print(1000*cnt-n)
            break
    
resolve()

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

int A[10];

int main() {
  cin >> A[0] >> A[1] >> A[2];

  sort(A, A + 3);

  cout << stoi(to_string(A[2]) + to_string(A[1])) + stoi(to_string(A[0])) << endl;
}

Measured memory_bytes: 256
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

n = int(input())
a = list(map(int,input().split()))

li = [0,0,0]

for i in range(n):
    if a[i]%4 == 0:
        li[0] += 1
    elif a[i]%2 == 1:
        li[1] += 1
    elif a[i]%2 == 0:
        li[2] += 1

if (li[0] >= li[1]-1 and li[2]==0) or (li[0] >= li[1]):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 15020
k, n = map(int, input().split())
alis = list(map(int, input().split()))
dlis = []
for i in range(n-1):
    dlis.append(alis[i+1]-alis[i])
dlis.append(alis[0]-alis[-1]+k)
print(sum(dlis) - max(dlis))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

constexpr int INF=1e9;
int d[1252][1252];
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int h, w, cx, cy, gx, gy;
  char s[1252][1252];
  cin>>h>>w>>cx>>cy>>gx>>gy;
  --cx;--cy;--gx;--gy;
  REP(i, h){
    REP(j, w){
      cin>>s[i][j];
    }
  }
  REP(i, h){
    REP(j, w){
      d[i][j]=INF;
    }
  }
  d[cx][cy]=0;
  deque<pair<pii, int>> que;
  que.push_front(make_pair(pii(cx, cy), 0));
  while(que.size()){
    auto xyd=que.front();que.pop_front();
    auto xy=xyd.first;
    int sx=xy.first, sy=xy.second, sd=xyd.second;
    REP(i, 4){
      int tx=sx+dx[i], ty=sy+dy[i];
      if(tx<0 || tx>=h || ty<0 || ty>=w || s[tx][ty]=='#'){
        continue;
      }
      if(d[tx][ty]<=sd){
        continue;
      }
      d[tx][ty]=sd;
      que.push_front(make_pair(pii(tx, ty), sd));
    }
    FOR(i, -2, 3){
      FOR(j, -2, 3){
        int tx=sx+i, ty=sy+j;
        if(tx<0 || tx>=h || ty<0 || ty>=w || s[tx][ty]=='#'){
          continue;
        }
        if(d[tx][ty]<=sd+1){
          continue;
        }
        d[tx][ty]=sd+1;
        que.push_back(make_pair(pii(tx, ty), sd+1));
      }
    }
  }
  // REP(i, h){
  //   REP(j, w){
  //     cout<<d[i][j]<<" \n"[j==w-1];
  //   }
  // }
  cout<<(d[gx][gy]==INF ? -1 : d[gx][gy])<<'\n';
  return 0;
}


Measured memory_bytes: 9808
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
//const int MOD=998244353;
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[1000001];
vector<ll>prime;

void seive(int limit)
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=limit;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=limit;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=limit;i++)if(!isPrime[i])prime.pb(i);
}

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

    ll dp[k+1]{0};

    for(ll i=k;i>=1;i--){
    dp[i]=power(k/i,n);
    ll extra=0;
    for(int j=2*i;j<=k;j+=i)
    {
        extra=(extra+dp[j]+M)%M;
    }
    dp[i]=(dp[i]-extra+M)%M;
    dp[i]=(dp[i]+M)%M;
    }

    ll ans=0;

    for(int i=1;i<=k;i++)
    {
        ans=(ans+(i*dp[i])+M)%M;
    }
    cout<<ans;
}


Measured memory_bytes: 4388
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String args[]) throws Exception{
    	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    	boolean closed= true;
    	int N= Integer.parseInt( br.readLine() );
    	String[] user= new String[N];
    	for(int i=0;i<N;i++){
    		user[i]= br.readLine();
    	}
    	Arrays.sort(user);
    	
    	int Q= Integer.parseInt( br.readLine() );
    	String key= new String();
    	for(int i=0;i<Q;i++){
    		key= br.readLine();
    		if( Arrays.binarySearch(user, key) >=0 ){
    			if(closed){
    				System.out.println("Opened by "+key);
    				closed= false;
    			} else{
    				System.out.println("Closed by "+key);
    				closed= true;
    			}
    		} else{
    			System.out.println("Unknown "+key);
    		}
    	}
    }
}

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


int main() {
  int N;
  cin >> N;
  
  vector<int> Xn(N);
  for (int i=0; i<N ;i++){
    cin >> Xn.at(i);
  }
  
  int sum = 10000000;
  
  for (int i=1; i<101;i++){
  int neko = 0;
   for (int j=0; j<N ;j++){
     neko = neko + (Xn.at(j)-i)*(Xn.at(j)-i);
   }
   if (neko < sum){
     sum = neko;
   }
  }
  cout << sum << endl;
  
  return 0;
}



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

int main() {
  int ans=INFINITY;
  int a;
  cin>>a;
  int b;
  int c;
  for(int i=0;i<a;i++){
    b=0;
    cin>>c;
    while (c%2==0){
      b++;
      c/=2;
    }
    ans=min(ans,b);
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 256
from math import ceil, log2

N, K = map(int, input().split())

Pr = 0.0
for dice in range(1, min(N + 1, K)):  # まだ勝ってない
    # 何回表が出たらよい?
    k = ceil(log2(K / dice))
    Pr += 1.0 / (2 ** k)

if K <= N:  # さいころだけで勝つ
    Pr += N - K + 1

Pr /= N
print(Pr)


Measured memory_bytes: 3060
tmp = gets.chomp.split.map(&:to_i)
a = tmp[0]
b = tmp[1]
answer = []
c= a/b.to_f
d = c.round(8)
# p "c =#{c}"
answer.push(a/b)
answer.push(a%b)
answer.push(sprintf( "%.8f", d ))

puts answer.join(' ')

Measured memory_bytes: 8836
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        Arrays.sort(a);
        System.out.println(a[n-1-(m-1)] < Math.ceil(sum / (4.0*m)) ? "No" : "Yes");
        sc.close();

    }

}


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

int main(){
	int n;
	cin>>n;
	int count=0;
	rep(i,n){
		ll a;
		cin>>a;
		while(a%2==0){
			count++;
			a/=2;
		}
	}
	puts(count);
}

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

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
} comb(200001);

int main() {
  int n, m;
  cin >> n >> m;
  if (n < m) swap(n, m);
  if (n - m > 1) {
    cout << 0 << endl;
    return 0;
  }

  mint ans = 1;
  rep(i, n) {
    ans *= (i + 1);
    if (i < m) ans *= (i + 1);
  }
  if (n == m) ans *= 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll res = 0;
    ll sum = 0;
    ll xor_sum = 0;
    int right = 0;

    rep(left, n){
        while(right < n && (sum + a[right]) == (xor_sum ^ a[right])){
            sum += a[right]; xor_sum ^= a[right];
            ++right;
        }

        int num = right - left;
        // res += (num + 1) * num / 2;
        res += num;

        if(right == left) ++right;
        else{
            sum -= a[left];
            xor_sum ^= a[left];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    s[i]='x';
  }
  cout << s<< endl;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define FOR(i,a,b) for (ll i = (a) ; i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

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<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい


void Main(){
	ll H, W, K, count=0, ans=0, bl=0;
	cin >> H >> W >> K;
	vector<string> c(H);
	rep(i, H){
		cin >> c[i];
	}



	rep(i, 1<<H){
		rep(j, 1<<W){
			count = 0;
			rep(s, H){
				if(i>>s&1) continue;
				rep(t, W){
					if(j>>t&1) continue;
					if(c[s][t] == '#') count++;
				}
			}
			if(count == K){
				ans++;
			}
		}
	}

	cout << ans << endl;



}

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

  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

int main() {
    cin >> n;
    vector<int> P(n, 0);
    vector<int> pos(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> P.at(i);
        P.at(i)--;
        pos.at(P.at(i)) = i;
    }

    int ans = 0; int cnt = 1;
    for(int i = 0; i < n-1; ++i) {
        if(pos.at(i+1) > pos.at(i)) cnt++;
        else {
            chmax(ans, cnt);
            cnt = 1;
        }
    }
    chmax(ans, cnt);

    cout << n-ans << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }


int main()
{
	ll H, W; cin >> H >> W;
	ll h, w;
	rep( i, H )
	{
		rep( j, W )
		{
			string s; cin >> s;
			if ( s == "snuke" )
				h = i, w = j;
		}
	}

	printf( "%c%d\n", 'A' + w, h + 1 );

	return ( 0 );
}


Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <istream>
#include <sstream>
#include <cstdlib>
using namespace std;

int main()
{
	vector<int> a;
	int b;
	int i;
	int j;
	int f = 0;

	for(i=0;i<6;i++)
	{
		cin >> b;
		a.push_back(b);
	}

	for (i = 0; i < 6; i++) 
	{
		for (j = 0; j < 6; j++)
		{
			if (abs(a[i] - a[j]) > a[5])
			{
				f = 1;
			}
		}
	}
	
	if (f == 1)
	{
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}

}

Measured memory_bytes: 256
n,k,c=map(int,input().split())
s=input()
l=[0]*n
r=[0]*n
mini=0
maxi=n-1
numl=1
numr=k
for i in range(n):
  if s[i]!='x' and i>=mini:
    l[i]=numl
    numl+=1
    mini=i+(c+1)
for i in reversed(range(n)):
  if s[i]!='x' and i<=maxi:
    r[i]=numr
    numr-=1
    maxi=i-(c+1)
for i in range(n):
  if l[i]!=0 and l[i]==r[i]:
    print(i+1)

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

int main() {
  vector<int> haiku(3), ans = {5, 5, 7};
  for(int i=0; i<3; i++) {
    cin >> haiku.at(i);
  }
  sort(haiku.begin(), haiku.end());
  if (haiku == ans) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a%2!=b%2) cout<<"IMPOSSIBLE"<<endl;
	else cout<<(a+b)/2<<endl;
}*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int f[55];
	cin>>n;
	int num=0;
	for(int i=1;i<=n;i++)
	{
		cin>>f[i];
		if(f[i]!=i) num++;
	}
	if(num<=2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

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

int main() {
	int x;
	cin >> x;
	if (x % 10 == x % 1000 / 100) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
mod = 10**9 +7
n, a, b = map(int, input().split())

nb = str(bin(n))[2:]
nblis = []
for k in range(len(nb)):
  if nb[-k-1] == '1':
    nblis.append(k)

two = [2]
for k in range(len(nb)-1):
  two.append(two[-1]*two[-1]%mod)


ans = 1
for item in nblis:
  ans = ans * two[item] %mod



bi = str(bin(mod-2))[2:]
blis = []
for k in range(len(bi)):
  if bi[-k-1] == '1':
    blis.append(k)


def modinv(N):
  if N == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(len(bi)):
      li.append(N%mod)
      N = N*N%mod
    for item in blis:
      res = res * li[item] %mod
    return res

ans_a = 1
for k in range(n-a+1, n+1):
  ans_a = ans_a*k%mod
amother = 1
for k in range(2, a+1):
  amother = amother * k % mod
ans_a = ans_a*modinv(amother)%mod


ans_b = 1
for k in range(n-b+1, n+1):
  ans_b = ans_b*k%mod
bmother = 1
for k in range(2, b+1):
  bmother = bmother * k % mod  
ans_b = ans_b*modinv(bmother)%mod

print((ans-ans_a-ans_b-1)%mod)

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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)

int32_t main() { fastio;
	int n; cin >> n;
	vector<int> arr(n + 1);
	for (int i = 0; i < n - 1; i++) {
		int x; cin >> x;
		arr[x]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << arr[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 4780
main=do
 [n,x]<-map read.words<$>getLine
 a<-map read.words<$>getLine
 print(f a x n 0)
  where f _ _ 1 k = k
        f a x n k | (a!!0)+(a!!1)>x = f ((if (a!!0)-x>0 then 0 else (x-(a!!0))):(drop 2 a)) x (n-1) (k+(a!!0)+(a!!1)-x)
                  | otherwise       = f (tail a) x (n-1) k

Measured memory_bytes: 36220
#include <iostream>
using namespace std;
int main(){
  int x,h,m,s;
  cin>>x;
  h=x/3600;
  m=(x-h*3600)/60;
  s=(x-h*3600)-m*60;
  cout<<h<<":"<<m<<":"<<s<<endl;
  return 0;
}



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

int main(void){
    int n, count, _count;
    char **p;
    char x;

    scanf("%d", &n);
    p = malloc(sizeof(char *) * n);
    for(int i = 0; i < n; i++){
        p[i] = malloc(sizeof(char) * 51);
        scanf("%s", p[i]);
    }

    x = 'a';
    while(x <= 'z'){
        count = 0;
        for(int i = 0; i < n; i++){
            _count = 0;
            for(int j = 0; j < strlen(p[i]); j++) if(p[i][j] == x) _count++;
            if(_count == 0){
                count = 0;
                break;
            }else if(count > _count || i == 0){
               count = _count;
            }
        }
        for(int i = 0; i < count; i++) printf("%c", x);
        x++;
    }

    printf("\n");
    
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = (1<<29);
const int INFF = 0x7fffffff;
const ll LINF = (1ll<<60);
const ll LINFF = 0x7fffffffffffffff;
const long double PI = 3.14159265359;

#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define prec(x) cout << fixed << setprecision(x)
#define sz(x) (int)x.size()
#define _log2(x) 31-__builtin_clz(x)

#define hash sodnf9843bsd
#define right iadjfof23n3okd
#define pqueue priority_queue
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define len length
#define endl '\n'

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll a, ll b){return uniform_int_distribution<ll>(a, b)(rng);}

int n;
double dp[333][333][333] = {};
bool vis[333][333][333] = {};

double solve(int a, int b, int c){
    if (a+b+c == 0) return 0;
    if (a < 0 || b < 0 || c < 0) return 0;

    if (vis[a][b][c] == false){
        vis[a][b][c] = true;

        dp[a][b][c] = 1;
        dp[a][b][c] += (double)a/n*solve(a-1, b, c);
        dp[a][b][c] += (double)b/n*solve(a+1, b-1, c);
        dp[a][b][c] += (double)c/n*solve(a, b+1, c-1);
        dp[a][b][c] *= (double)n/(a+b+c);
    }
    return dp[a][b][c];
}

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

    int cnt[5] = {};
    cin>>n;
    _fi(n){
        int x;cin>>x;
        cnt[x]++;
    }

    prec(10);
    cout << solve(cnt[1], cnt[2], cnt[3]) << endl;

    return 0;
}


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

int main (void){
  long long int n,t = 0,k = 0,m = 1000,o = 0;

  cin >> n;

  vector<long long int> a(n,0);
  vector<long long int> max(n,0);

  for(int i = 0;i < n;i++){
    cin >> a[i];
    if(i != 0){
      if(a[i] > a[max[t]]){
        max[t] = i;
      }else{
        t++;
        max[t] = i;
      }
    }
  }
  o = t;
  t = 0;

  for(int i = 0;i >= 0;i++){
    if(max[t] != 0 && i == 0){
      k = m / a[0];
      m = m - k*a[0];
      m = m + k*a[max[t]];
      k = 0;
      t++;
      if(t>o){
        break;
      }
    }else if(max[t] == 0){
      if(i == 0){
        t++;
      }else{
        break;
      }
    }else{
      k = m / a[max[t-1]+1];
      m = m - k*a[max[t-1]+1];
      m = m + k*a[max[t]];
      k = 0;
      t++;
      if(t>o){
        break;
      }
    }
  }

  cout << m << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    vector<int>vec;
    vector<int> output;
    int size;
    int firstNum;
    int secondNum = 0;
    
    cin >> size;

    for(int i = 0;i < size;++i){
        cin >> firstNum;
        if(firstNum != 2){
            cin >> secondNum;
        }
        switch (firstNum) {
            case 0:
                vec.push_back(secondNum);
                break;
            case 1:
                output.push_back(vec.at(secondNum));
                break;
            default:
                vec.pop_back();
                break;
        }
    }
    for(int i = 0;i < output.size();++i){
        printf("%d\n",output.at(i));
        if(i + 1 > output.size()){
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 4044
c = [list(map(int, input().split())) for _ in range(3)]
a = [0, 0, 0]
b = [0, 0, 0]
b[0] = c[0][0] - a[0]
b[1] = c[0][1] - a[0]
b[2] = c[0][2] - a[0]
a[1] = c[1][0] - b[0]
a[2] = c[2][0] - b[0]

cnt = 0
for i in range(3):
    for j in range(3):
        if c[i][j] == a[i]+b[j]:
            cnt += 1

print('Yes' if cnt == 9 else 'No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define equals(a, b) (fabs((a) - (b)) < EPS)

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

const int INF = 1 << 28;
const ll LLINF = 1LL << 60;
const double EPS = 1e-9;

int main()
{
    int N;
    int A;
    int mul = 1;
    int ans = 1;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A;
        if(A % 2 == 0) ans *= 2;
        mul *= 3;
    }

    cout << mul - ans << endl;

    return (0);
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<set>


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

using namespace std;

const int N = 111111;

int main()
{
	int n;
	cin>>n;
	
	int a[N];
	rep(i,n){
		cin>>a[i];
		a[i]--;
	}
	
	int cnt = 0;
	
	rep(i,n){
		if(a[a[i]]==i)cnt++;
	}
	
	printf("%d\n",cnt/2);
	
	
	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define per(i,x,y) for (int i=(x);i>=(y);i--)
#define ll long long
using namespace std;
const int N=2e5+5;
int L,n; ll ans,sf[N],pr[N],a[N],x,y;
void get1(int x,int y){
	::x=x+(y-x)/2,::y=y-((y-x)-(y-x)/2-1);
}
void get2(int x,int y){
	::x=x-(x-1)/2,::y=y+(x-1-(x-1)/2-1);
}
int main(){
	scanf("%d%d",&L,&n);
	rep (i,1,n) scanf("%lld",&a[i]),pr[i]=a[i],sf[i]=L-a[i]; a[n+1]=L;
	rep (i,1,n) pr[i]+=pr[i-1];
	per (i,n,1) sf[i]+=sf[i+1];
	ans=max(a[n],L-a[1]);
	rep (i,0,n-1){
		get1(i,n);
		ll tmp1=pr[x]-pr[i]-a[i]*(x-i),tmp2=sf[y];
		if (n+1-y>x-i) tmp2=tmp2*2-(L-a[y]),tmp1*=2;
		else tmp1=tmp1*2-(a[x]-a[i]),tmp2*=2;
		ans=max(ans,a[i]*(n-i+1)+tmp1+tmp2);
	}
	per (i,n,2){
		get2(i,1);
		ll tmp1=sf[x]-sf[i]-(L-a[i])*(i-x),tmp2=pr[y];
		if (y>i-x) tmp2=tmp2*2-a[y],tmp1*=2;
		else tmp1=tmp1*2-(a[i]-a[x]),tmp2*=2;
		ans=max(ans,(L-a[i])*i+tmp1+tmp2);
	}
	printf("%lld\n",ans);
	return 0;
}

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

typedef long long ll;

int main(){
  ll n; cin >> n;

  ll a=1, b=n;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      a = i; b = n/i;
    }
  }

  cout << to_string(b).length() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e;
  string s,ss,sss;
  cin>>s>>ss;
  a=0;
  for(int i=0;i<3;i++)
    if(s[i]==ss[i])a++;
  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
	int A=0;
	int B=0;
	int C=0;
	bool Data[100]={};
	bool Flag=true;
	scanf(" %d %d %d",&A,&B,&C);
	for(int i=1;;i++){
		int Temp=A*i%B;
		if(Temp==C){
			break;
		}else if(Data[Temp]==true){
			Flag=false;
			break;
		}
		Data[Temp]=true;
	}
	printf("%s",Flag==true?"YES":"NO");
	return 0;
}

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

int main(void)
{
  int n, m, l, i, j, k;
  long long sum;
  int a[101][101] = {}, b[101][101] = {};
  cin >> n >> m >> l;
  for (i = 0; i < n; i++){
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 0; i < m; i++){
    for (j = 0; j < l; j++) {
      cin >> b[i][j];
    }
  }
  for (i = 0; i < n; i++){
    for (j = 0; j < l; j++) {
      sum = 0;
      if (j == l - 1) break;
      for (k = 0; k < m; k++){
        sum += a[i][k] * b[k][j];
      }
      cout << sum << " ";
    }
    for (k = 0; k < m; k++) sum += a[i][k] * b[k][j];
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
def BubbleSort(c,n):
 for i in range(n):
  for j in range(n-i-1):
   if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 return c

def SelectionSort(c,n):
 for i in range(n):
  m=i
  for j in range(i,n):
   if c[j][1]<c[m][1]:m=j
  c[i],c[m]=c[m],c[i]
 return c

n=int(input());c=input().split()
b=BubbleSort(c.copy(),n)
s=SelectionSort(c.copy(),n)
print(*b)
print("Stable")
print(*s)
print(["Not s","S"][b==s]+"table")


Measured memory_bytes: 5616