akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define pb push_back
#define ms(a, x) memset(a, x, sizeof(a))
#define forn(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i) 
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int mod = 1e9;
const int N = 1e5+10;
/*=======================================================================*/

int n, h[N], sum, k;
int f[N];

int main() {
   scanf("%d%d", &n, &k);
   for1(i, n) {
      scanf("%d", &h[i]);
   }
   ms(f, inf);
   f[n] = 0;
   for(int i = n; i > 1; i--) {
      for(int j = 1; j <= k; ++j) {
         if(i - j < 1) break;
         f[i-j] = min(f[i-j], f[i] + abs(h[i] - h[i-j]));
      }
   }
   cout << f[1] << endl;
   return 0;
}

Measured memory_bytes: 1024
// +build ignore
package main

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

const D int = 60
const MAX_N int = 200005

var to [D][MAX_N]int

func solve(sc *scanner, wr *bufio.Writer) int {
	N := sc.i()
	K := sc.i()
	_ = to[D-1][MAX_N-1]
	for i := 0; i < N; i++ {
		to[0][i] = sc.i() - 1
	}

	for i := 1; i < D; i++ {
		for j := 0; j < N; j++ {
			to[i][j] = to[i-1][to[i-1][j]]
		}
	}

	p := 0
	for i := D; i >= 0; i-- {
		if K&(1<<i) != 0 {
			p = to[i][p]
		}
	}

	fmt.Println(p + 1)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

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

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

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

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

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

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

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

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


Measured memory_bytes: 96916
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt");
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }
    

    static object process(TextReader input) {
        int n = int.Parse(input.ReadLine());
        //int[] ll = ToIntArray(input.ReadLine(), n);
        
        int[] tb = new int[1001];

        var spl =input.ReadLine().Split(' ');
        for (int i = 0; i < n; i++) {
            var x = int.Parse(spl[i]);
            tb[x]++;
        }

        long count = 0;

        for(int i=1000; i>0; i--) {
            if (tb[i] == 0) continue;
            count += Combination(tb[i],3);

            for(int j=i-1; j>0; j--) {
                if (tb[j] == 0) continue;

                if (i < j + j) {
                    count += tb[i] * Combination(tb[j],2);
                }
                count += tb[j] * Combination(tb[i],2);

                for(int k=j-1; k>0; k--) {
                    if (i >= j + k) break;
                    if (tb[k] == 0) continue;

                    if(i < j+ k) {
                        count += tb[i] * tb[j] * tb[k];
                    }
                }
            }
        }

        return count;
    }

    static long Combination(long m, long n) {
        if (m < n) return 0;
        if (m == n || n == 0) return 1;

        long ans = 1;
        for (long i = 1; i <= n; i++) {
            ans = ans * (m - i + 1) / i;
        }
        return ans;
    }
}


Measured memory_bytes: 11136
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<61;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=200001;

int n,k;
vi a(M);

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		a[A]++;
	}
	vi b;
	for(int i=0;i<M;i++) if(a[i]) b.push_back(a[i]);
	sort(b.begin(),b.end());
	int S=b.size();
	if(S<=k) cout<<0<<endl;
	else{
		int res=0;
		for(int i=0;i<S-k;i++) res+=b[i];
		cout<<res<<endl;
	}
}

Measured memory_bytes: 2168
#include	<stdio.h>
int	main(void)
{
	int a,b,c;
	int j = 1;
	int count=0;
	scanf("%d %d %d",&a,&b,&c);

	while(count != 1000){  //出ない間繰り返す
		if((a + a*j) % b != c){  //ない
			count++;
			j++;
		}else{
			printf("YES");
			break;
		}
	}
	if(count == 1000) printf("NO");
	
	return	0;
}


Measured memory_bytes: 128
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

ans = 0
for karen in range(n):
    a = list(map(int, input().split()))
    sum = c
    for frederica in range(m):
        sum += a[frederica] * b[frederica]
    if sum > 0:
        ans += 1

print(ans)

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

int main(){
  int H,W,x = 0;
  while(1){
    cin >> H;
    cin >> W;
    x = 0;
    if(H == 0 && W == 0){
      break;
    }
    for(int i = 0;i < H;i++){
      for(int j = 0;j < W;j++){
        if(x % 2 == 0){
          cout<<'#';
        }else{
          cout<<'.';
        }
        x += 1;
      }
      x = i+1;
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int A, B;
	cin >> A >> B;
	int I = 0;
	string S;
	int cnt = 0;
	for (int i = A; i <= B; i++) {
		I = i;
		S = to_string(I);
		if (S[0] == S[4] &&
			S[1] == S[3]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
N = int(input())
a = list(map(int, input().split()))
C = [0] * 3
for ai in a:
    if ai % 4 == 0:
        C[2] += 1
    elif ai % 2 == 0:
        C[1] += 1
    else:
        C[0] += 1
while C[0] > 0:
    if C[2] > 0:
        C[0] -= 1
        C[2] -= 1
    else:
        if C[0] == 1 and C[1] == 0:
            print('Yes')
            sys.exit()
        else:
            print('No')
            sys.exit()
print('Yes')

Measured memory_bytes: 20032
// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

const int Size = 1000001;

array<int, Size> g_Table{};

array<int, Size> g_PrimeTable{};

bool IsPrimeImpl(int n)
{
    if(n < 2)
    {
        return false;
    }
    if(n == 2)
    {
        return true;
    }
    if(n % 2 == 0)
    {
        return false;
    }
    for(int i = 3; i <= static_cast<int>(sqrt(n)); i += 2)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    return true;
}

bool IsPrime(int n)
{
    if(g_PrimeTable[n] == 1)
    {
        return false;
    }
    if(g_PrimeTable[n] == 2)
    {
        return true;
    }
    auto isPrime = IsPrimeImpl(n);
    g_PrimeTable[n] = isPrime ? 2 : 1;
    return isPrime;
}

void SetupTable()
{
    g_Table[2] = 0;
    g_Table[3] = 1;
    for(int i = 5; i < Size - 1; i += 2)
    {
        g_Table[i - 1] = g_Table[i - 2];
        if(IsPrime(i) && IsPrime((i + 1) / 2))
        {
            g_Table[i] = g_Table[i - 1] + 1;
        }
        else
        {
            g_Table[i] = g_Table[i - 1];
        }
    }
}

int main(int, const char**)
{
    SetupTable();
#if 0
    rep(i, 15)
    {
        printf("%d: %d\n", i, g_Table[i]);
//        cout << g_Table[i] << endl;
    }
#endif
#if 0
    rep(i, 15)
    {
        printf("%d: %d\n", i, g_PrimeTable[i]);
//        cout << g_Table[i] << endl;
    }
#endif
    int q;
    cin >> q;
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        cout << g_Table[r] - g_Table[l - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 11460
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    int H, W,h,w;

    cin >> H >> W;
    cin >> h >> w;
    int ans = H*W;
    ans -= h * W;
    ans -= w * (H - h);
    cout << ans;
    return 0;
}

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

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    ModComb mc(1000001);
    for(int i = 0; i <= x; i++){
        if(i*2 > y || 2*(y-i*2) != x-i)  continue;
        ans += mc.nCk(i + (x-i)/2, i);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
N = int(input())

works = []
for _ in range(N):
    A, B = map(int, input().split())
    works.append((A, B))

works = sorted(works, key=lambda x: x[1])

t = 0
flg = True
for w in works:
    t += w[0]
    if t > w[1]:
        flg = False

if flg:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 74712
import java.util.Scanner;

public class Main {
	static long max =Long.MIN_VALUE;
	static long[] C;
	static int[] P;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String string = sc.next();

		if (N % 2 ==1) {
			System.out.println("No");
		} else {
			if (string.substring(0, N/2).equals(string.substring(N/2, N)) ) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 35884
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> cnt(n, 0);
    for (int i = 0; i < n;i ++) {
        cin >> a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    int ans = 0;
    for (int i = 0 ;i < n; i++) {
        ans += (cnt[i] * (cnt[i] - 1)) / 2;
    }
    for (int i = 0 ;i < n; i++) {
        ans -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        cout << ans + (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2 << "\n" ;
        ans += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
    }
}
/*

*/


Measured memory_bytes: 5760
import scala.io.StdIn.readLine

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */
object Main extends App {
  val arg = readLine.split(" ").map(_.toInt)
  val N = arg.apply(0)
  val A = arg.apply(1)
  val B = arg.apply(2)

  val x = readLine.split(" ").map(_.toLong)

  val ans: Long = 1.until(N).foldLeft(0.toLong)((s, i) => s + math.min((x(i) - x (i - 1)) * A, B)
  )

  println(ans)
}

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

int main()
{
	int a[64], b[64], c[64], d[64];

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

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

	for (int i = 0; i < m; ++i) 
		cin >> c[i] >> d[i];

	for (int i = 0; i < n; ++i) {
		
		int ans = 1;
		int mini = 1e9 + 9;

		for (int j = 0; j < m; ++j) {
			if (mini > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				ans = j + 1;
				mini = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			}
		}

		cout << ans << endl;
	}

}


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

#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define ins insert
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'

vi v, c;
int a[12][12];
int x, mn;

void dfs(int i, vi v, int cost) {
    if(i == c.size()) {
        bool flag = true;
        for(int j = 0; j < v.size(); j++) {
            if(v[j] < x) {
                flag = false;
                break;
            }
        }
        if(flag == true) {
            mn = min(mn, cost);
        }
        return;
    }
    vi nv = v;
    dfs(i + 1, v, cost);
    for(int k = 0; k < nv.size(); k++) {
        nv[k] += a[i][k];
    }
    dfs(i + 1, nv, cost + c[i]);
}

signed main() {
    int n, m;
    cin >> n >> m >> x;
    c.resize(n);
    mn = INT_MAX;
    for(int i = 0; i < n; i++) {
        cin >> c[i];
        for(int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    v.assign(m, 0);
    dfs(0, v, 0);
    if(mn == INT_MAX) {
        cout << -1;
    }
    else {
        cout << mn;
    }
}

Measured memory_bytes: 3636
/*
      author : Nishikawa
      created: 06.08.2020 22:14:50
*/

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


int main(){
    for(int i=1; i<=5; i++){
        int n; cin >> n;
        if(n==0) cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;
struct UnionFind
{
  vector<int> par;   // par[i]が親を表す
  vector<int> _size; // _size[i]でそのノードの属しているサイズを返す

  // コンストラクタ
  UnionFind(int n)
  {
    _size = vector<int>(n);
    par = vector<int>(n);
    for (int i = 0; i < n; i++)
    {
      par[i] = i;
      _size[i] = 1;
    }
  }

  // データxの根を求める
  int root(int x)
  {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]); // 木構造の縮約を行っている
  }

  // xとyの親が違うとき、マージする。そのときyの根がxの根の子になる
  void merge(int x, int y)
  {
    int rootx = root(x);
    int rooty = root(y);
    if (rootx == rooty)
      return;
    par[rooty] = rootx;
    int s = _size[rooty] + _size[rootx];
    _size[rooty] = s;
    _size[rootx] = s;
  }

  // xの属している集団のサイズ
  int size(int x)
  {
    return _size[x];
  }

  // 同じグループに属しているか
  bool isSame(int x, int y)
  {
    return root(x) == root(y);
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  REP(i, n)
  {
    int po;
    cin >> po;
    po--;
    p[i] = po;
  }

  UnionFind uf(n);

  REP(i, m)
  {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    uf.merge(x, y);
  }

  int ans = 0;
  REP(i, n)
  {
    if (uf.root(p[i]) == uf.root(i))
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
int A[500001];
 int n;
 int maxh(int i){
       int l=i*2;
       int r=i*2+1;

       int max;
       if(l<=n&&A[l]>A[i]){max=l;}
       else max=i;
       if(r<=n&&A[r]>A[max]){max=r;}

       if(max!=i){
               int tmp=A[i];A[i]=A[max];A[max]=tmp;
               maxh(max);
               }
       }

 int main(){
       int i;
       
       scanf("%d",&n);
       for(i=1;i<=n;i++){
                 scanf("%d",&A[i]);
                 }
       for(i=n/2;i>=1;i--){
                 maxh(i);
                 }
       for(i=1;i<=n;i++){
                 printf(" %d",A[i]);
                 }
       printf("\n");
       return 0;
       }


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a;
  cin>>a;
  cout<<a/3<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[3010][3010];
int main(){
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<t.size();j++){
            if(s[i]==t[j])
            dp[i+1][j+1]=dp[i][j]+1;
            else{
                dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            }
        }
    }
  /*  for(int i=0;i<=s.size();i++){
        for(int j=0;j<=t.size();j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    int i=s.size(),j=t.size();
    string ans="";
    while (i!=0&&j!=0){
         if(dp[i-1][j]==dp[i][j]){
            i--;
        }else if(dp[i][j-1]==dp[i][j])
        {
            j--;
        }else{
            i--;
            j--;
            ans+=s[i];
        }
        
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  string sa,sb,sc; cin >> sa >> sb >> sc;
  queue<char> qa,qb,qc;
  rep(i,sa.size()){
    qa.push(sa[i]);
  }
  rep(i,sb.size()){
    qb.push(sb[i]);
  }
  rep(i,sc.size()){
    qc.push(sc[i]);
  }
  char current = 'a';
  while(1){
    if(current=='a'){
      if(qa.empty()) break;
      current=qa.front();
      qa.pop();
      continue;
    }
    if(current=='b'){
      if(qb.empty()) break;
      current=qb.front();
      qb.pop();
      continue;
    }
    if(current=='c'){
      if(qc.empty()) break;
      current=qc.front();
      qc.pop();
      continue;
    }
  }
  cout << (char)toupper(current);
  return 0;
}


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

using namespace std;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}
using ll = long long;
struct RangeMinimumQuery {
  using type = ll;
  static type id() { return INT_MAX; }
  static type op(const type &l, const type &r) { return std::min(l, r); }
};

template <typename M>
class SegmentTree {
  using T = typename M::type;
  int n;
  std::vector<T> node;

 public:
  // v を基に初期化
  SegmentTree(const std::vector<T> &v) {
    // n は v.size() 以上の最小の2冪
    n = 1;
    while (n < int(v.size())) n *= 2;
    node.resize(2 * n, M::id());

    // i の子 -> 2*i+1, 2*i+2 , 親 -> (i-1)/2
    for (int i = 0; i < int(v.size()); i++) node[i + n] = v[i];
    for (int i = n - 1; i >= 0; i--)
      node[i] = M::op(node[2 * i], node[2 * i + 1]);
  }
  // Monoid::id 初期化
  SegmentTree(int _n) {
    // n は v.size() 以上の最小の2冪
    n = 1;
    while (n < _n) n *= 2;
    node.resize(2 * n, M::id());
  }
  // x 番目を val に更新
  void update(int x, T val) {
    x += n;
    node[x] = val;
    while (x >>= 1) {
      node[x] = M::op(node[2 * x], node[2 * x + 1]);
    }
  }
  // v[x] を M::op(v[x], val) に更新
  void operation(int x, T val) {
    x += n;
    node[x] = M::op(node[x], val);
    while (x >>= 1) {
      node[x] = M::op(node[2 * x], node[2 * x + 1]);
    }
  }
  // [a, b) の op
  T query(int l, int r) {
    l += n;
    r += n;
    T retl = M::id(), retr = M::id();
    while (l < r) {
      if (l & 1) retl = M::op(retl, node[l++]);
      if (r & 1) retr = M::op(node[--r], retr);
      l >>= 1;
      r >>= 1;
    }
    return M::op(retl, retr);
  }
};

constexpr int inf = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  SegmentTree<RangeMinimumQuery> seg(n + 2);
  map<int, vector<int>> pos;
  seg.update(n, 0);
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') continue;
    ll mi = seg.query(i + 1, min(n + 1, i + m + 1));
    seg.operation(i, mi + 1);
    ll d = seg.query(i, i + 1);
    if (d <= n) {
      pos[d].push_back(i);
      //cerr << i << " " << d << endl;
    }
  }
  int dist = seg.query(0, 1);
  if (dist > n) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> ret;
  int cur = 0;
  for (int i = dist - 1; i > 0; i--) {
    assert(pos.count(i));
    sort(pos[i].begin(), pos[i].end());
    auto itr = upper_bound(pos[i].begin(), pos[i].end(), cur);
    assert(itr != pos[i].end());
    ret.push_back((*itr) - cur);
    cur = *itr;
  }
  ret.push_back(n - cur);
  printv(ret);
}


Measured memory_bytes: 14072
#include <stdio.h>

int m, n, field[90][90], visited[90][90], count, countm;

int dfs(int x, int y);

int main()
{
	int i, j;
	while(1) {
		scanf("%d", &m);
		scanf("%d", &n);
		if(m == 0 && n == 0) break;
		for(i = 0; i < m; i++) {
			for(j = 0; j < n; j++) {
				scanf("%d", &field[i][j]);
			}
		}
		/* 初期化 */
		count = 0;
		for(i = 0; i < 90; i++) {
			for(j = 0; j < 90; j++) {
				visited[i][j] = 0;
			}
		}
		/* DFS */
		for(i = 0; i < m; i++) {
			for(j = 0; j < n; j++) {
				if(field[i][j]) {
					dfs(i, j);
				}
				count = 0;
			}
		}

		printf("%d\n", countm);
		countm = 0;


	}
	return 0;
}

int dfs(int x, int y)
{
	visited[x][y] = 1;
	if(!field[x][y]) return -1;
	else count++;
	if(count > countm) countm = count;
	if(x + 1 <= m && !visited[x + 1][y]) dfs(x + 1, y);
	if(y + 1 <= n && !visited[x][y + 1]) dfs(x, y + 1);
	if(x - 1 >= 0 && !visited[x - 1][y]) dfs(x - 1, y);
	if(y - 1 >= 0 && !visited[x][y - 1]) dfs(x, y - 1);
	visited[x][y] = 0;
	count--;
	return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void dfs(int start,vector<bool>&vis,vector<vector<int>>&adj,vi &dp){
	vis[start]=true;
	for (int i=0;i<adj[start].size();i++){
		if (!vis[adj[start][i]])dfs(adj[start][i],vis,adj,dp);
		dp[start]=max(dp[start],1+dp[adj[start][i]]);
	}
}

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	int n,e;
	cin>>n>>e;
	vector<vector<int>>adj(n+1);
	int u,v;
	rep(i,0,e){
		cin>>u>>v;
		adj[u].pb(v);
	}
	vi dp(n+1,0);
	vector<bool>vis(n+1,false);
	for (int i=1;i<=n;i++){
		if (!vis[i])dfs(i,vis,adj,dp);
	}
	cout<<*max_element(dp.begin(),dp.end())<<endl;
	return 0;
}

Measured memory_bytes: 9600
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    s = rs()
    t = ['x' for c in s]
    print("".join(t))


if __name__ == "__main__":
    main()


Measured memory_bytes: 12496
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;

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

  int h, w, m;
  cin >> h >> w >> m;
  vector<Pii> t(m);
  for (auto &x: t) cin >> x.first >> x.second;

  set<Pii> t_set;
  for (auto &x: t) t_set.insert(x);

  unordered_map<int, int> rowcount, colcount;
  for (auto &x: t) {
    rowcount[x.first]++;
    colcount[x.second]++;
  }

  vector<int> rowmax, colmax;
  int rcmax = 0, ccmax = 0;
  for (auto &x: rowcount) {
    if (x.second > rcmax) {
      rcmax = x.second;
      rowmax.clear();
    }
    if (x.second == rcmax) {
      rowmax.push_back(x.first);
    }
  }
  for (auto &x: colcount) {
    if (x.second > ccmax) {
      ccmax = x.second;
      colmax.clear();
    }
    if (x.second == ccmax) {
      colmax.push_back(x.first);
    }
  }

  bool nodup = false;
  for (auto &x: rowmax) {
    for (auto &y: colmax) {
      if (t_set.find(Pii(x, y)) == t_set.end()) {
        nodup = true;
        break;
      }
    }
    if (nodup) break;
  }

  int ans = rcmax + ccmax;
  if (!nodup) ans--;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 50972
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto V=vecin(N);
	
	REP(i,N){
		int q = V[i];
		int j=i-1;
		for(;j>=0;j--){
			if(V[j]>q){
				V[j+1] = V[j];
			}
			else break;
		}
		V[j+1] = q;

		REP(k,N-1){
			cout << V[k] << ' ';
		}
		out(V[N-1]);
	}

	return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	ll r;
	cin>>r;
	cout<<r*r*3;
	return 0;
}

Measured memory_bytes: 256
//abc168

#include <bits/stdc++.h>
using namespace std;

int main() {

  string n;
  string ans  = "hon";
  cin >> n;

  if(n.at(n.size()-1)=='3'){
    ans = "bon";
  }else if(n.at(n.size()-1)=='0' || n.at(n.size()-1)=='1' || n.at(n.size()-1)=='6' || n.at(n.size()-1)=='8'){
    ans = "pon";
  }else{
    ans  = "hon";
  }

  cout << ans << endl;

}


Measured memory_bytes: 3592
x,y = map(int,input().split())
ans =0
if x == 1:
	ans += 300000
elif x == 2:
	ans += 200000
elif x == 3 :
	ans += 100000

if y == 1:
	ans += 300000
elif y == 2:
	ans += 200000
elif y == 3 :
	ans += 100000

if x == 1 and y == 1:
	ans += 400000

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli  long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
lli inf=9223372036854775807;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
#define UNASSIGNED 0  
//&& + - ! ~ ++ - - () *
lli ani;
int main()
{
	lli n;
	cin>>n;
	lli temp=0;
	lli a[n];
	for(lli i=0;i<n;i++){
		cin>>a[i];
		temp=temp^a[i];
	}
	for(lli i=0;i<n;i++){
		lli c=temp^a[i];
		cout<<c<<" ";
		//cin>>a[i];
		//temp=temp^a[i];
	}
	
	
 
    return 0;
}

Measured memory_bytes: 5112
#include<iostream>
using namespace std;
void nhapkt(int &n)
{
	cin>>n;
}
void NhapMT(int a[], int n)
{
	for(int i=0;i<n;i++)
	{
		 cin>>a[i];
	}
}
bool isSNT(int k)
{
	if(k==2) return true;
    if(k<2 || k%2==0) return false;
    for (int i = 3; i*i<=k ; i=i+2)
    {
        if (k%i==0) return false;
    }
    return true;
}
void CountPN(int a[],int n)
{
	int d=0;
	for(int i=0;i<n;i++)
	{
		if(isSNT(a[i]))
			d++;
	}
	cout<<d<<endl;
}
int main()
{
	int n;
	int a[10000];
	nhapkt(n);
	NhapMT(a,n);
	CountPN(a,n);
}

Measured memory_bytes: 3088
import sys
sys.setrecursionlimit(10 ** 6)


MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


def dfs(n, free):
    cnt = free
    rst = True
    for e in edge[n]:
        if status[e] == -1:
            cnt += 1
            status[e] = cnt
            rst &= dfs(e, 1)
    if cnt > K - 1:
        rst &= False
    return rst


N, K = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

modFacts, invs = prepare(K)


status = [-1] * N
status[0] = 0
result = dfs(0, 0)
if result:
    ans = 1
    for s in status:
        ans *= (K - s)
        ans %= MOD
else:
    ans = 0

print(ans)


Measured memory_bytes: 88112
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

int pref[1000000];
int ttt[1000000];
vector<pii> l[1000000];
void solve() {
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < k; i++) {
    cin >> pref[i] >> ttt[i];
    l[pref[i]].push_back({ttt[i], i});
  }
  for(int i = 1; i <= n; i++) {
    sort(l[i].begin(), l[i].end());
    int id = 0;
    for(pii out: l[i]) {
      ttt[out.second] = ++id;
    }
  }
  for(int i = 0; i < k; i++) {
    printf("%06d%06d\n", pref[i], ttt[i]);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 31232
import sys

a = int(sys.stdin.readline())
b = int(sys.stdin.readline())
c = int(sys.stdin.readline())
d = int(sys.stdin.readline())
e = int(sys.stdin.readline())
k = int(sys.stdin.readline())

if e - a > k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 38256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, l int
	fmt.Scanf("%d %d", &n, &l)

	sum := 0
	min := 99999999
	for i := 0; i < n; i++ {
		sum += l + i
		abs := int(math.Abs(float64(l + i)))
		if min > abs {
			min = abs
		}
	}

	if l+n <= 0 {
		fmt.Print(sum + min)
	} else {
		fmt.Print(sum - min)
	}
	return
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

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

int main(){
    ll a, b, c, d; cin>>a>>b>>c>>d;

    ll lcm = c * d / gcd(c, d);

    //cout << (b / c + b / d - b / lcm) << endl;
    //cout << ((b / c + b / d - b / lcm) - (a / c + a / d - a / lcm)) << endl;
    cout << (b - a + 1) - ((b / c + b / d - b / lcm) - ((a - 1) / c + (a - 1) / d - (a - 1) / lcm)) << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
import math
def deno(x):
    if x >= K:
        return 1
    else:
        count = math.ceil(math.log(K/x, 2))
        return 1 / (2 ** count)
pro = sum(map(deno, range(1,N+1))) / N
print(pro)

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

int main() {
  while (true) {
    int m, d; cin >> m >> d;
    if (m == 0 && d == 0) break;
    int month[12] = {31,29,31,30,31,30,31,31,30,31,30,31};

    for (int i = 0; i < m - 1; i++) d += month[i];

    switch (d % 7) {
    case 1:
      cout << "Thursday" << endl;
      break;
    case 2:
      cout << "Friday" << endl;
      break;
    case 3:
      cout << "Saturday" << endl;
      break;
    case 4:
      cout << "Sunday" << endl;
      break;
    case 5:
      cout << "Monday" << endl;
      break;
    case 6:
      cout << "Tuesday" << endl;
      break;
    default:
      cout << "Wednesday" << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
const int N = 188;
int dpr[N][N][N];
int dpd[N][N][N];
int new_dpr[N][N][N];
int new_dpd[N][N][N];
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	vector<string> grd(h);
	for (int i = 0; i < h; i++) cin >> grd[i];
	vector<vector<int>> cum(h + 1, vector<int>(w + 1, 0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cum[i + 1][j + 1]
				= cum[i + 1][j] + cum[i][j + 1] - cum[i][j]
				+ (int)(grd[i][j] == '.');
		}
	}
	auto get_sum = [&] (int i1, int j1, int i2, int j2) {
		return cum[i2][j2]
			- cum[i2][j1] - cum[i1][j2] + cum[i1][j1];
	};
	auto is_mono = [&] (int i1, int j1, int i2, int j2) {
		int sum = get_sum(i1, j1, i2, j2);
		int area = (i2 - i1) * (j2 - j1);
		return (sum == 0 || sum == area);
	};
	for (int i1 = 0; i1 < h; i1++) {
		for (int j1 = 0; j1 < w; j1++) {
			for (int i2 = i1 + 1; i2 <= h; i2++) {
				int ok = j1, ng = w + 1;
				while (ng -  ok > 1) {
					int mid = (ok + ng) >> 1;
					if (is_mono(i1, j1, i2, mid)) ok = mid;
					else ng = mid;
				}
				dpr[i1][j1][i2] = ok;
			}
			for (int j2 = j1 + 1; j2 <= w; j2++) {
				int ok = i1, ng = h + 1;
				while (ng - ok > 1) {
					int mid = (ok + ng) >> 1;
					if (is_mono(i1, j1, mid, j2)) ok = mid;
					else ng = mid;
				}
				dpd[i1][j1][j2] = ok;
			}
		}
	}
	for (int it = 0; ; it++) {
		if (dpr[0][0][h] == w) {
			cout << it << endl;
			return 0;
		}
		for (int i1 = 0; i1 < h; i1++) {
			for (int j1 = 0; j1 < w; j1++) {
				for (int i2 = i1 + 1; i2 <= h; i2++) {
					int j2 = dpr[i1][j1][i2];
					if (j2 < w) j2 = dpr[i1][j2][i2];
					new_dpr[i1][j1][i2] = j2;
				}
				for (int j2 = j1 + 1; j2 <= w; j2++) {
					int i2 = dpd[i1][j1][j2];
					if (i2 < h) i2 = dpd[i2][j1][j2];
					new_dpd[i1][j1][j2] = i2;
				}
			}
		}
		for (int i1 = 0; i1 < h; i1++) {
			for (int j1 = 0; j1 < w; j1++) {
				for (int i2 = i1 + 1; i2 <= h; i2++) {
					int ok = new_dpr[i1][j1][i2], ng = w + 1, md;
					while (ng - ok > 1) {
						md = (ok + ng) >> 1;
						if (new_dpd[i1][j1][md] >= i2) ok = md;
						else ng = md;
					}
					dpr[i1][j1][i2] = ok;
				}
				for (int j2 = j1 + 1; j2 <= w; j2++) {
					int ok = new_dpd[i1][j1][j2], ng = h + 1, md;
					while (ng - ok > 1) {
						md = (ok + ng) >> 1;
						if (new_dpr[i1][j1][md] >= j2) ok = md;
						else ng = md;
					}
					dpd[i1][j1][j2] = ok;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 103808
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

int a, b, c, d;
int main() {
    cin >> a >> b >> c >> d;
    int f = 0;
    if(a%2 == 0 && c == a/2 && b%2 == 0 && d == b/2) f ^= 1;
    printf("%.6f %d\n", (a*1.0*b)/2.0, f);
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B, C = [0]*Q, [0]*Q
    for i in range(Q):
        B[i], C[i] = map(int, input().split())
    # 個数を持つ
    # Biの個数 O(1),C[i]の個数 O(1) 更新 O(1) 総和O(1)

    count = Counter(A)
    tot = sum(A)
    for i in range(Q):
        b = count[B[i]]
        c = count[C[i]]
        count[C[i]] += b
        count[B[i]] = 0
        tot = tot - B[i]*b + C[i]*b
        print(tot)

    return


if __name__ == '__main__':
    main()


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

int main(){
  int N, K;
  cin >> N >> K;
  
  int var = 1;
  for (int i = 0; i < N; i++){
    if (var * 2 < (var + K)){
      var = var * 2;
    }else{
      var = var + K;
    }
  }
  
  cout << var << endl;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=505;
int n,m,q,a[mxn][mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	cin >> n >> m >> q;
	for(int i=0; i<m; i++){
		int l,r; cin >> l >> r;
		a[l][r]++;
	}
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			a[i][j]+=a[i][j-1];
			
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			a[i][j]+=a[i-1][j];
			
	while(q--){
		int l,r;
		cin >> l >> r;
		cout << a[r][r]+a[l-1][l-1]-a[l-1][r]-a[r][l-1] << endl;
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string S;
    cin >> S;

    if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) cout << "Bad\n";
    else cout << "Good\n";
}

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

const int INF = 100000000;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

int main()
{
    int h, w;
    cin >> h >> w;
    SegmentTree<int> seg(w, [](int a, int b){return min(a, b);}, INF);
    for(int i = 0; i < w; i++) seg.set(i, 0);
    seg.build();
    set<int> st;
    for(int i = 0; i < w; i++) st.insert(i);
    for(int i = 1; i <= h; i++){
        int a, b;
        cin >> a >> b;
        a--;
        int r = INF;
        while(true){
            auto itr = st.lower_bound(a);
            if(itr == st.end() || *itr > b) break;
            r = min(r, seg[*itr] + b - *itr);
            seg.update(*itr, INF);
            st.erase(itr);
        }
        if(r < INF && b < w){
            st.insert(b);
            seg.update(b, r);
        }
        int ans = seg.query(0, w) + i;
        if(ans >= INF) cout << -1 << endl;
        else cout << ans << endl;
    }
}


Measured memory_bytes: 14436