akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

// nCr
map<ll, ll> po;
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(ll n, ll r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N, M;
ll K;

int main() {
  scanf("%d %d %lld", &N, &M, &K);

  ll comb_v = comb(N * M - 2, K - 2);

  ll sum = 0;
  FOR(i, 1, N) {
    ll m = (N - i) * M * M % MOD;
    sum += i * m * comb_v % MOD;
    sum %= MOD;
  }
  FOR(i, 1, M) {
    ll m = (M - i) * N * N % MOD;
    sum += i * m * comb_v % MOD;
    sum %= MOD;
  }
  printf("%lld\n", sum);
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    ll ans = 0;
    for (int i = 1; i <= n - 1; i++)
    {
        int k = (n - 1) - i / 2;
        ans += a[k];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();

		int n = b - a;
		int m = c - b;

		if (n == m) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    cin >> n;
    
    int count = 0;
    for(int i=1; i<=n; i++) {
        string s = to_string(i);
        if(s.length()%2!=0) count++;
    }

    cout << count << endl;

    return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string C = Console.ReadLine();
            string D = Console.ReadLine();
            string ans = "NO";
            if (C[0] == D[2] && C[1] == D[1] && C[2] == D[0])
            {
                ans = "YES";
            }

            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }
    


    public class Calculation
    {
        
    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 11092
fun main() {
    nextInt()
    val valueMap = mutableMapOf<Int, Int>()
    var sum = 0L
    nextIntList().forEach {
        sum += it
        valueMap[it] = valueMap.getOrDefault(it, 0) + 1
    }
    val q = nextInt()
    repeat(q) {
        val (b, c) = nextIntList()
        val bNum = valueMap.getOrDefault(b, 0)
        val cNum = valueMap.getOrDefault(c, 0)
        sum += c.minus(b).times(bNum)
        valueMap.remove(b)
        valueMap[c] = cNum + bNum
        println(sum)
    }
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }


Measured memory_bytes: 76624
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	long long pre1 = 1, pre2 = 2, res;
	if(N == 0) cout << pre2 << endl;
	else if(N == 1) cout << pre1 << endl;
	else {
		for (int i = 2; i <= N; i++)
		{
			res = pre1 + pre2;
			pre2 = pre1;
			pre1 = res;
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> L(N), R(N);
	int min_R = OVER9000, max_L = 0, ans = 0;
	for(int i = 0; i < N; i++) {
		cin >> L[i] >> R[i];
		min_R = min(min_R, R[i]);
		max_L = max(max_L, L[i]);
		ans = max(ans, R[i]-L[i]+1);
	}
	if(min_R >= max_L) ans += min_R-max_L+1;
	vector< pair<int, int> > I(N);
	for(int i = 0; i < N; i++) I[i] = {L[i], i};
	sort(begin(I), end(I));
	multiset<int> SR;
	for(int i = 0; i < N; i++) SR.insert(R[i]);
	for(int i = 0; i < N-1; i++) {
		if(I[i].ff > min_R) break;
		SR.erase(SR.find(R[I[i].ss]));
		if(*begin(SR) >= max_L)
			ans = max(ans, min_R-I[i].ff+1 + *begin(SR)-max_L+1);
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 6528
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]

x,y=[int(i) for i in input().split()]
ans=0
biglist=[a,b,c]
for group in biglist:
    if (x in group) and (y in group):
        ans+=1
        
if ans==1:
    print("Yes")
else:
    print("No")

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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  int A[q];
  rep (i, q) cin >> A[i];

  int score[n];
  rep (i, n) score[i] = k-q;

  rep (i, q) score[A[i]-1]++;

  rep (i, n) {
    if (score[i] <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  } 

  return 0;
}


Measured memory_bytes: 1408
import fractions
a,b,c,d = map(int,input().split())
a = a-1
cd = fractions.gcd(c,d)
cm = c*d//cd
blk = cm - cm//c - cm//d + 1
M = (b//cm)*blk + b%cm - (b%cm)//c - (b%cm)//d
m = (a//cm)*blk + a%cm - (a%cm)//c - (a%cm)//d
print(int(M-m))

Measured memory_bytes: 5048
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long sum = 0;
		int cnt = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			if (a[i] < 0) {
				cnt++;
			}
			int abs = Math.abs(a[i]);
			sum += abs;
			min = Math.min(min, abs);
		}
		if (cnt % 2 == 1) {
			System.out.println(sum - 2 * min);
		} else {
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 52660
#include<stdio.h>
int main(){
    int a[3];
    int b;
    int d;
    for(int i=0;i<3;i++)
    scanf("%d",&a[i]);
    d=2*a[0]+a[1];
    for(int i=0;i<3;i++){
        for(int j=0;j<3 && j!=i;j++){
            b=2*a[i]+a[j];
            if(b<=d)
            d=b;

        }
    }
    int sum=a[0]+a[1]+a[2];
    for(int i=0;i<3;i++){
        if(sum-a[i]<=d)
        d=sum-a[i];
    }
    printf("%d",d);
    
}

Measured memory_bytes: 1724
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let tele = Array.make_matrix n 62 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun a ->
      tele.(i).(0) <- a - 1
  done;
  for j = 0 to 60 do
    for i = 0 to n - 1 do
      tele.(i).(j + 1) <- tele.(tele.(i).(j)).(j)
    done
  done;
  Printf.printf "%d\n" @@
  succ @@
  List.fold_left (fun c i ->
    if k land (1 lsl i) = 0
    then c
    else tele.(c).(i)) 0 @@
  List.init 62 Fun.id



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

ll gcd(ll a, ll b){
    ll r = a%b;
    ll re;
    if(r == 0) re = b;
    else re = gcd(b, r);
    return re;
}

int main(){
    int n;
    cin >> n;
    vector<ll> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];
    ll ans = 1;
    for(int i = 0; i < n; i++){
        ans = ans * (t[i] / gcd(ans, t[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while(1) {
		string x;
		cin >> x;
		if(x[0] == '0') break;
		
		int sum = 0;
		REP(i, x.size()) {
			sum += (x[i] - '0');
		}
		cout << sum << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1188
#include<vector>
#include<iostream>
#include<string>
#include<utility>
using namespace std;

#define X first
#define Y second

const double eps =  1e-9;
typedef long double ld;
int main(){
  ld x[4];
  ld y[4];
  while(cin >>x[0]>>y[0]>>x[1]>>y[1] >>x[2]>>y[2]>>x[3]>>y[3]){
    if(min(x[1],x[3])<max(x[0],x[2]) || min(y[1],y[3])< max(y[0],y[2]))cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
  }
}

Measured memory_bytes: 1216
n = int(input())
t = list(map(int, input().split()))
m = int(input())
ans = 0
for i in range(m):
    p, x = map(int, input().split())
    j = t[p-1]
    t[p-1] = x
    print(sum(t))
    t[p-1] = j


Measured memory_bytes: 3060
#python3
from bisect import bisect_left
INF = int(1e9)

def main():
    n, m = map(int, input().split())
    a = [int(i) for i in input().split()]
    a.sort()
    ac = [0]
    for i in range(n):
        ac.append(ac[i]+a[i])

    def chk(x):
        cnt = 0
        for i in range(n):
            pos = bisect_left(a, x - a[i])
            cnt += (n-pos)
        return (cnt < m)

    l = 0
    r = INF
    while r-l > 1: 
        mid = (l + r)//2
        if chk(mid):
            r = mid
        else:
            l = mid

    cnt = 0
    sgm = 0
    for i in range(n):
        pos = bisect_left(a, r - a[i])
        cnt += (n-pos) 
        sgm += a[i] * (n-pos) + (ac[n] - ac[pos]) 

    print(sgm+(m-cnt)*l)
main()


Measured memory_bytes: 14268
n=int(input())
data=[]
for i in range(n):
    x,l=map(int,input().split())
    data.append([x+l,x-l])
data.sort()
ans=1
arm=data[0][0]
for i in range(n):
    if arm<=data[i][1]:
        ans+=1
        arm=data[i][0]
print(ans)

Measured memory_bytes: 21612
#include <iostream>
#include <algorithm>

int N;
int a;

int main(void){
    int min = 1000;
    int max = 0;

    std::cin >> N;
    for(int i=0; i<N; ++i){
        std::cin >> a;
        min = std::min(min, a);
        max = std::max(max, a);
    }
    std::cout << (max-min) << std::endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,d[4]={0};
  char s[301];
  scanf("%s",s);
  for(i=0;s[i];i++){
    if(s[i]=='K')d[0]++;
    if(s[i]=='U')d[1]++;
    if(s[i]=='P')d[2]++;
    if(s[i]=='C')d[3]++;
  }
  for(i=1;i<4;i++){
    if(d[0]>d[i])d[0]=d[i];
  }
  printf("%d\n",d[0]);
  return 0;
}

Measured memory_bytes: 536
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n,a,b;

int main() {
    cin >> n >> a >> b;
    vector<int> p(n);
    int sa=0;
    int sb=0;
    int sc=0;
    
    REP(i,n){
        cin >> p[i];
        if(p[i]<=a){
            sa++;
        }else if(p[i]<=b){
            sb++;
        }else{
            sc++;
        }
    }
    int res = min(sa,sb);
    put(min(res,sc));
    return 0;
}




Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = input[0];
            var B = input[1];

            Console.WriteLine(Ans(A, B));
        }

        static int Ans(int A, int B)
        {
            if (A >= 13) return B;
            else if (A >= 6) return B / 2;
            else return 0;
        }
    }
}


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

int main() {
    string S;
    cin >> S;
    long long K;

    cin >> K;

    for(int i=0;i<S.size();i++){
        if(S.at(i)!='1') {
            cout << S[i] << endl;
            return 0;
        }
        else if(K-1==i){
            cout << 1 << endl;
            return 0;
        }
        else if(i==S.size()-1 &&S[i]=='1'){
            cout << 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
<?php
$n = trim(fgets(STDIN));

for ($i = 1; $i <= $n; $i++) {
  $x = $i;
  if ($x % 3 == 0) {
    echo " $i";
    continue;
  }

  do {
    if ($x % 10 == 3) {
      echo " $i";
      break;
    }
    $x = intval($x / 10);
  } while ($x);
}

echo "\n";



Measured memory_bytes: 9220
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n;cin >> n;
    vector<pair<int, int>> a(n);
    REP(i, n) { 
        cin >> a[i].first;
        a[i].second = i;
    }
    ASC(a);
    REP(i, n) cout << a[i].second + 1 << " ";
    return 0;
}


Measured memory_bytes: 1664
import java.lang.Math.pow
import java.math.BigInteger

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

private fun readLong() = readLn().toLong() // single int
private fun readLongs() = readStrings().map { it.toLong() }

fun main(){
    val n = readInt()
    val numList = readLongs()

    //var ans: Long = 1
    var ans: BigInteger = BigInteger.valueOf(1)
    val limit: Long = pow(10.0, 18.0).toLong()

    if(numList.contains(0)){
        ans = BigInteger.valueOf(0)
    }else{
        for(i in numList){
            ans *= BigInteger.valueOf(i)
            if(ans > BigInteger.valueOf(limit)){
                ans = BigInteger.valueOf(-1)
                break
            }
        }
    }

    println(ans)
}



Measured memory_bytes: 63492
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int n;

int main() {
    cin >> n;
    int m = n%10;
    if (m == 3) cout << "bon" << endl;
    else if (m == 0 || m == 1 || m == 6 || m == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

ll gao(ll x, ll y) {
    if (x <= y) return y - x;
    return x - y + 2;
}

int main() {
    ll x, y; cin >> x >> y;
    ll res = min({gao(x,y), gao(-x, y) + 1, gao(x, -y) + 1});
   
    cout << res << endl;
}

Measured memory_bytes: 3576
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$N = $key->A[0];
//$N=$A*$BのA,Bをどうやって求める？
$res=$N;
$m=9999999999;
for($i=1;$i<=(int)(sqrt($N));$i++) {
  $r = (int)($N / $i);
  if (($r * $i) == $N) {
    $m = max(strlen($r),strlen($i));
    if ($m < $res) {
      $res = $m;
    }
  }
}
printf("%d\n",$res);


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

#define db(x) cerr << #x ": " << (x) << '\n';

#define int long long

using namespace std;

typedef long long ll;

typedef long double ld;

const int oo = 1e18;

int N, A, B;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> A >> B;

    int K = A+B;

    int as = (N/K)*A;

    N %= K;

    if(N >= A)
    {
        as += A;
    }
    else
    {
        as += N;
    }

    cout << as << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;


int main() {
	ll i, j;
	ll N;
	cin >> N;
	vector<double> X, Y;
	for (i = 0; i < N; i++) {
		double x, y;
		cin >> x >> y;
		X.push_back(x);
		Y.push_back(y);
	}
	double all = 0;
	for (i = 0; i < N - 1; i++) {
		for (j = i + 1; j < N; j++) {
			all += sqrt(pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2));
		}
	}
	double ans = all * (double)(N - 1) / (double)N / (double)(N - 1) * (double)2;
	cout << fixed;
	cout << setprecision(10) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
const int maxn=2e5+7,inf=0x3f3f3f3f,mod=1e9+7;

ll dp[70][2][2];
int a[70];

ll dfs(int pos,bool lim=1,bool add=0)
{
    if(pos<0) return add==0;
    if(dp[pos][lim][add]!=-1) return dp[pos][lim][add];
    ll res=0;
    int up=lim?a[pos]:1;
    if(up==1)  //当前1
    {
        if(add)
            res=(res+dfs(pos-1,lim,1))%mod;
        else
        {
            res=(res+dfs(pos-1,lim,0))%mod;
            res=(res+dfs(pos-1,lim,1))%mod;
        }
    }
    //0
    if(add)
    {
        res=(res+dfs(pos-1,lim&&up==0,1))%mod;  //1 0
        res=(res+dfs(pos-1,lim&&up==0,0))%mod;  //1 1
    }
    else res=(res+dfs(pos-1,lim&&up==0,0))%mod;  //0 0
    return dp[pos][lim][add]=res;
}

ll solve(ll x)
{
    memset(dp,-1,sizeof(dp));
    int pos=0;
    while(x)
    {
        a[pos++]=x&1;
        x/=2;
    }
    return dfs(pos-1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    cout<<solve(n)<<'\n';
    return 0;
}


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

int abs(int a){
  if(a>=0) return a;
  else return -a;
}

int compare(const void* x, const void* y){
  if(*(int*)x<*(int*)y) return -1;
  else if(*(int*)x>*(int*)y) return 1;
  return 0;
}

int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  int *h;
  h=(int*)malloc((n+1)*sizeof(int));
  for(int i=1;i<=n;i++) scanf("%d",&h[i]);

  int *dp;
  dp=(int*)malloc((n+1)*sizeof(int));
  dp[1]=0;

  if(k>=n-1){
    printf("%d",abs(h[n]-h[1]));
    return 0;
  }

  for(int i=2;i<=1+k;i++){
    dp[i]=abs(h[i]-h[1]);
  }
  for(int i=2+k;i<=n;i++){
    int *temp;
    temp=(int*)malloc(k*sizeof(int));
    for(int j=0;j<k;j++){
      temp[j]=dp[i-j-1]+abs(h[i]-h[i-j-1]);
    }
    qsort(temp,k,sizeof(int),compare);
    dp[i]=temp[0];
  }
  printf("%d\n",dp[n]);
  return 0;
}


Measured memory_bytes: 41472
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    priority_queue<ll> p;
    priority_queue<ll> q;
    priority_queue<ll> z;
    ll n;
    REP(i, a) {
        cin >> n;
        p.emplace(n);
    }
    REP(i, x) {
        z.emplace(p.top());
        p.pop();
    }
    REP(i, b) {
        cin >> n;
        q.emplace(n);
    }
    REP(i, y) {
        z.emplace(q.top());
        q.pop();
    }
    REP(i, c) {
        cin >> n;
        z.emplace(n);
    }

    ll ans = 0;
    REP(i, x + y) {
        ans += z.top();
        z.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 7920
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------

a,b,c,k = mapi()
res = 0
res,k = min(k,a),max(0,k-min(k,a))
k = max(k-min(k,b),0)
res-=min(k,c)
print(res)


Measured memory_bytes: 67996
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int, int> pi;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MKP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
const int INF = 999999;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll MOD = 1000000007;
int a,b,c;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> a >> b >>c;
	cout << max({a,b,c}) - min({a,b,c}) << endl;
		return 0;
}
 


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


ll n,m,v,p;
ll a[100010];

bool ok(ll k){
    vll b;
    rep(i,n){
        if(i==k) continue;
        b.pb(a[i]);
    }
    ll base=a[k]+m;
    ll cnt=0;
    bool can=true;
    rep(i,n-1){
        if(i<p-1) cnt+=m;
        else if(base>=b[i]) cnt+=min(m,base-b[i]);
        else can=false;
    }
    if(!can) return false;
    else if(cnt>=m*(v-1)) return true;
    else return false;
}




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    cin>>n>>m>>v>>p;
    rep(i,n) cin>>a[i];
    sort(a,a+n);
    reverse(a,a+n);
    ll left=0,right=n-1;
    if(ok(n-1)){
        cout<<n<<endl;
        // cerr<<"FJl"<<endl;
        return 0;
    }
    while(right-left>1){
        ll mid=(left+right)/2;
        // cerr<<mid<<"$";;
        if(ok(mid)){
            left=mid;
            // cerr<<"YES"<<endl;
        }
        else right=mid;
    }
    cout<<left+1<<endl;
    return 0;
}

Measured memory_bytes: 2916
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 2e3 + 7;
const int M = 1e9 + 7;
int S[N], T[N], sum[N][N];

int mod(int val)
{
	return (val % M + M) % M;
}

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; ++i)
		scanf("%d", &S[i]);
	for (int i = 0; i < m; ++i)
		scanf("%d", &T[i]);

	for (int i = 0; i <= max(n, m); ++i)
		sum[0][i] = sum[i][0] = 1;

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
		{
			int val = S[i] == T[j] ? sum[i][j] : 0;
			sum[i + 1][j + 1] = mod(mod(mod(sum[i + 1][j] + sum[i][j + 1]) - sum[i][j]) + val);
		}

	printf("%d", sum[n][m]);

	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;


int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  ll ans = -1;
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      ll tmp = a[i] * a[j];
      string S = to_string(tmp);
      bool ok = true;
      for(int i = 1; i < S.size(); i++) {
        if(S[i] - S[i-1] != 1) ok = false;
      }
      if(ok) chmax(ans, tmp);
    }
  }
  cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3288
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

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


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

int main(){

  int n;
  cin >> n;

  int num;
  vector<int> v;

  for(int i; i<n; ++i){
    cin >> num;
    v.push_back(num);
  }

  sort(v.begin(),v.end());

  int ans = v.back() - v.front();
  cout << ans <<endl;

  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  vector<bitset<500>> a(n);
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    a[i] = bitset<500>(tmp);
  }
  bitset<500> total(0);

  rep(i, n) total ^= a[i];

  rep(i, n) cout << (total ^ a[i]).to_ulong() << " ";
  cout << endl;

  return 0;
}


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

template <int MOD=1000000007>
struct Modular {
  int value;
  static const int MOD_value = MOD;

  Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
  Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

  Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
  Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
  Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}

  friend Modular mexp(Modular a, long long e) {
    Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
    return res;
  }
  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }

  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
  friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
  friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

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

  vector<int> s(n + 1), t(m + 1);
  for (int i = 1; i <= n; ++i)  cin >> s[i];
  for (int i = 1; i <= m; ++i)  cin >> t[i];

  Modular<> dp[m+1], tmp[m+1];
  for (int i = 0; i <= m; ++i)  dp[i] = 1;

  for (int i = 1; i <= n; ++i) {
    memset(tmp, 0, sizeof tmp);
    for (int j = 1; j <= m; ++j) {
      if (s[i] == t[j])
        tmp[j] += dp[j-1];
    }
    for (int j = 1; j <= m; ++j) {
      tmp[j] += tmp[j-1];
      dp[j] += tmp[j];
    }
  }

  cout << dp[m] << '\n';
}



Measured memory_bytes: 256
using System;
using System.Linq;

namespace AGC034A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NABCD = CIN.IntArray();
            string S = CIN.String();
            var N = NABCD[0];
            var A = NABCD[1];
            var B = NABCD[2];
            var C = NABCD[3];
            var D = NABCD[4];

            var BiggerGoal = Math.Max(C, D);
            bool Rock = false;
            int maxF = 0;
            int curF = 0;
            for (var i = A - 1; i < BiggerGoal; i++)
            {
                if (S[i] == '#')
                {
                    if (Rock)
                    {
                        Console.WriteLine("No");
                        return;
                    }

                    Rock = true;
                    curF = 0;
                    continue;
                }

                if (i >= B - 2 && i <= Math.Min(C, D))
                {
                    curF++;
                    maxF = Math.Max(maxF, curF);
                }

                Rock = false;
            }

            if (D < C)
            {
                if (maxF < 3)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

struct pos{
  int x;
  int y;
};

int h,w;
char s[50][50];
int dist[50][50];

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


// x : 縦 y : 横  BFSバージョン
int main(){
  cin >> h >> w;

  int cnt=0;
  REP(i,h)REP(j,w){
    cin >> s[i][j];
    if(s[i][j]=='.')cnt++;
  }

  queue<pos> q;

  q.push({0,0});
  dist[0][0]=1;

  while(!q.empty()){
    int x = q.front().x;
    int y = q.front().y;
    q.pop();

    REP(i,4){
      int nx = x + dx[i];
      int ny = y + dy[i];

      if(nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
      if(s[nx][ny]=='#')continue;
      if(dist[nx][ny]!=0)continue;

      dist[nx][ny] = dist[x][y]+1;
      q.push({nx,ny});
    }

  }

  if(dist[h-1][w-1]==0){
    cout << -1 << endl;
  }else{
    cout << cnt - dist[h-1][w-1] << endl;
  }

}



Measured memory_bytes: 256
#coding:utf-8
from collections import deque
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def index(a,b):
    return str(min(a,b)) + "," +  str(max(a, b))

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n = II()

    g = {}
    t = {}
    ans = [1] * (n-1)
    k = [0] * (n+1)

    for i in range(n-1):
        a, b = LMIIS()
        if a in g:
            g[a].append(b)
        else:
            g[a] = [b]
        if b in g:
            g[b].append(a)
        else:
            g[b] = [a]
        t[index(a, b)] = i

    q = deque([[1, g[1][0]]])

    while len(q) > 0:
        a, b = q.pop()
        used = ans[t[index(a,b)]]
        if k[a] == 0:
            k[a] = 1
            color = 1
            for x in g[a]:
                if color == used:
                    color += 1
                if x == b:
                    continue
                ans[t[index(a, x)]] = color
                color += 1
                q.append([a,x])

        if k[b] == 0:
            k[b] = 1
            color = 1
            for x in g[b]:
                if color == used:
                    color += 1
                if x == a:
                    continue
                ans[t[index(b, x)]] = color
                color += 1
                q.append([b,x])

    print(max(ans))
    for i in range(n-1):
        print(ans[i])












if __name__ == '__main__':
    main()


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

for n in range(N):
    gx,gy=map(int,input().split())
    T=[[0 for i in range(gy+1)] for j in range(gx+1)]
    left=[[0 for i in range(gy+1)] for j in range(gx+1)]
    upper=[[0 for i in range(gy+1)] for j in range(gx+1)]
    p=int(input())
    
    for i in range(p):       
        x1,y1,x2,y2=map(int,input().split())
        if x1==x2:
            upper[x1][max(y1,y2)]=1
        if y1==y2:
            left[max(x1,x2)][y1]=1
            
    for i in range(gx+1):
        for j in range(gy+1):
            if i==0:
                left[i][j]=1
            if j==0:
                upper[i][j]=1
            
    for i in range(gx+1):
        for j in range(gy+1):
            if i==0 and j==0: 
                T[i][j]=1
            else:   
                if left[i][j]==1 and upper[i][j]==1:
                    T[i][j]=0
                elif left[i][j]==0 and upper[i][j]==1:
                    T[i][j]=T[i-1][j]
                elif left[i][j]==1 and upper[i][j]==0:
                    T[i][j]=T[i][j-1]
                else:
                    T[i][j]=T[i-1][j]+T[i][j-1]
    
    if T[gx][gy]==0:
        print("Miserable Hokusai!")
    else:
        print(T[gx][gy])




Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl;
#define coYES cout << "YES" << endl;
#define coyes cout << "yes" << endl;
#define coNo cout << "No" << endl;
#define coNO cout << "NO" << endl;
#define cono cout << "no" << endl;
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int n,c=0;
    cin >> n;
    vector<int> p(n);
    rep0(i,n){
        cin >> p[i];
        if(p[i]!=i+1) c++;
    }
    if(c>2) coNO
    else coYES
    return 0;
}

Measured memory_bytes: 3516
h, w, k = gets.split.map(&:to_i)

a = Array.new(h)
for i in 0...h
    a[i] = gets.chomp.chars
end

sum = 0
r = Array.new(h, 0)
c = Array.new(w, 0)
for i in 0...h
    for j in 0...w
        if a[i][j] == '#'
            r[i] += 1
            c[j] += 1
            sum += 1
        end
    end
end

ans = 0
for y in 0...(1<<h)
    for x in 0...(1<<w)
        t = 0
        #b = a.clone
        b = Marshal.load(Marshal.dump(a))
        for i in 0...h
            for j in 0...w
                b[i][j] = '-' if (((y & (1 << i)) != 0) || ((x & (1 << j)) != 0))
            end
        end

        for i in 0...h
            for j in 0...w
                if b[i][j] == '#'
                    t += 1
                end
            end
        end
        if t == k
            ans += 1
        end
    end
end

puts ans

Measured memory_bytes: 14352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

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

  int h, w, m; cin >> h >> w >> m;
  vector<pair<int, int>> in;

  vector<int> cnt_row(h, 0), cnt_col(w, 0);

  for (int i = 0; i < m; ++i) {
    int hh, ww; cin >> hh >> ww;
    --hh; --ww;
    in.emplace_back(hh, ww);
    ++cnt_row[hh]; ++cnt_col[ww];
  }

  int mx_row = *max_element(all(cnt_row));
  int mx_col = *max_element(all(cnt_col));
  int ans = mx_row + mx_col;
  int64 can = count(all(cnt_row), mx_row) * count(all(cnt_col), mx_col);
  if (can > m) {
    cout << ans << endl;
  } else {
    int bad = 0;
    for (auto e : in) bad += (cnt_row[e.first] + cnt_col[e.second] == ans);
    if (can > bad) {
      cout << ans << endl;
    } else {
      cout << ans - 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 9744
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
signed main(){
  string s;
  ll f=0,cun=0;
  cin>>s;
  if(s[0]!='A'){
    cout<<"WA\n";
    return(0);
  }else{
    for(ll i=1;i<s.size();i++){
      if(s[i] >= 'a' && s[i] <= 'z'){
        f++;
      }else if(i>=2 && i<=s.size()-2 && s[i]=='C'){
        f++;
        cun++;
      }
    }
    if(f==s.size()-1 && cun==1){
      cout<<"AC\n";
    }else{
      cout<<"WA\n";
    }
  }
  return(0);
}

Measured memory_bytes: 256
// 2020-08-23 14:45:57
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  string s;
  cin >> s;
  int sz = s.size();
  int a = -1, b = -1;
  rep(i, sz) {
    if(i >= 1 && s[i-1] == s[i]) {
      a = i;
      b = i+1;
      break;
    }
    if(i >= 2 && s[i-2] == s[i]) {
      a = i-1;
      b = i+1;
      break;
    }
  }
  cout << a << ' ' << b << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

using namespace std;
typedef long long ll;

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

	for(int i = 1; i <= 50000; i++){
		int temp = i * 1.08;
		if(temp == n){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;	
}


Measured memory_bytes: 256
n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P += [[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5)

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

using namespace std;

vector<string > result;

long long int numFromNumStr(string numStr){
    long long int ret = 0;
    long long int carrier = 1;
    while(!numStr.empty()){
        ret += atoi(&numStr[numStr.size()-1]) * carrier;
        carrier *= 10;
        numStr.pop_back();
    }
    return ret;
}


void solve(string done, string undone){
    if (undone.empty()){
        result.push_back(done);
        return;
    }
    solve(done + undone[0], undone.substr(1));
    solve(done + '+' + undone[0], undone.substr(1));
}


long long int numFromEquationString(string str){
    long long int num = 0;
    vector<int > idxList;
    vector<int > numList;
    idxList.push_back(-1);
    for (int i=0; i<str.length(); i++){
        if (str[i]=='+') idxList.push_back(i);
    }
    idxList.push_back(str.length());
    for (int i=0; i<idxList.size()-1; i++){
        num +=  numFromNumStr( str.substr(idxList[i]+1, idxList[i+1]-idxList[i] - 1) ) ;
    }
    return num;
}


int main(){
    string S;
    cin >> S;
    // cout << S.substr(1,2) << endl;
    // cout << S.substr(3) << endl;
    solve(S.substr(0,1), S.substr(1));
    long long int res = 0;
    for (int i=0; i<result.size(); i++){
        res += numFromEquationString(result[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int K;
  cin >> K;
  ll A[100010];
  for (auto i = 0; i < K; ++i) {
    cin >> A[i];
  }
  reverse(A, A+K);
  if (A[0] != 2) {
    cout << -1 << endl;
    return 0;
  }
  ll maxi = 3;
  ll mini = 2;
  for (auto i = 1; i < K; ++i) {
    ll tmini = (mini/A[i]) * A[i];
    if (mini > tmini) {
      tmini += A[i];
    }
    if (tmini > maxi) {
      cout << -1 << endl;
      return 0;      
    }
    ll tmaxi = (maxi/A[i]) * A[i] + A[i] - 1;
    maxi = tmaxi;
    mini = tmini;
  }
  cout << mini << " " << maxi << endl;
}


Measured memory_bytes: 1024
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(solve(s[0], s[1]));
    }
    static int solve(int n, int k) {
        int ans = (n-1+k-2)/(k-1);
        return ans;
    }
}

Measured memory_bytes: 20064