akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
#include <sys/resource.h>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 15;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;


void increaseStack() {
	const rlim_t kStackSize = 50 * 1024 * 1024;   // min stack size = 50 MB
	struct rlimit rl;
	int result;

	result = getrlimit(RLIMIT_STACK, &rl);
	if (result == 0) {
		if (rl.rlim_cur < kStackSize) {
			rl.rlim_cur = kStackSize;
		    result = setrlimit(RLIMIT_STACK, &rl);
		    if (result != 0) {
		    	fprintf(stderr, "setrlimit returned result = %d\n", result);
		    }
		}
	}
}


ll rec(int l, int r,  vector<int> & values, vector<vector<ll>> & memo) {
	if (l >= r) return 0;
	if(r - l == 1) return values[l] + values[r];
	if(memo[l][r] != -1) return memo[l][r];
	
	ll acc = inf;
	ll curAcc = accumulate(values.begin() + l, values.begin() + r + 1, 0l); 
	for (auto k = l; k < r; ++k) {
		acc = min(acc, rec(l, k, values, memo) + rec(k + 1, r, values, memo));
	}
	acc += curAcc;
	memo[l][r] = acc;
	return acc;
}

void solve() {
	int n; cin >> n;
	vector<int> values(n);
	for (auto &it : values) cin >> it;

	vector<vector<ll>> memo(n + 1, vector<ll>(n + 1, -1));
	ll ret = rec(0, values.size() - 1, values, memo);
	cout << ret;

}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}


Measured memory_bytes: 1536
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n-1],
    }
    let mut member = vec![0; n];
    for ai in a {
        member[ai - 1] = member[ai - 1] + 1
    }
    for people in member {
        println!("{}", people);
    }
}


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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e9, mxp = (1 << 9), maxn = (1 << 18);



void solve(int ci)
{
    int n;
    cin >> n;
    string s[4] = {"AC", "WA", "TLE", "RE"};
    map<string, int> mp;
    f(4) mp[s[i]] = i;
    int am[4] = {0};
    f(n)
    {
        string t;
        cin >> t;
        am[mp[t]]++;
    }
    f(4) cout << s[i] << " x " << am[mp[s[i]]] << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 3668
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位
int imos[2000000];
int ch[31][2000000];
int chend[2000000][31];
signed main() {
	//imos[i]は時刻2iを表す。時刻0は0、1は2、1.5は3。
	int N, H;
	vector<int> a, b;
	int bsum = 0, amax = -1;
	cin >> N >> H;
	for (int i = 0; i < N; i++) {
		int ain, bin;
		cin >> ain >> bin;
		a.push_back(ain);
		b.push_back(bin);
		if (amax < ain) amax = ain;
		bsum += bin;
	}
	//aの最大値よりダメが出る剣を全部投げる
	int ans = 0;
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	for (int i = 0; i < N; i++) {
		if (H <= 0) break;
		if (b[i] < amax) break;
		ans++;
		H -= b[i];
	}

	//いちばんつよい剣で切り続ける
	if (H > 0) {
		if (H%amax == 0) ans += H / amax;
		else ans += (H / amax + 1);
	}



	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 2036
#include <iostream>
using namespace std;
int main(){
//	int a[200000]={0};
	int temp;
	int k,n;
	int count;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>temp;
		if(temp>=k){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    readline = sys.stdin.readline

    mod = 10**9 + 7

    n = int(readline())
    A = list(map(int, readline().split()))

    sumA = sum(A) % mod
    ans = 0

    for i in A:
        sumA -= i
        ans += i * sumA
        ans %= mod

    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 31464
def make_divisors(n):
    if n==1:
        divisors=[1]
        return divisors
    else:
        divisors=[]
        for i in range(1,n):
            if i*i>n:
                break
            if n%i==0:
                divisors.append(i)
                if i!=n//i:
                    divisors.append(n//i)

        #divisors.sort()
        return divisors

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    ds=make_divisors(n)

    ans=float("inf")
    for a in ds:
        b=n//a
        a=str(a)
        b=str(b)
        ans=min(ans,max(len(a),len(b)))

    print(ans)
    
if __name__=="__main__":
    main()

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

int main(void)
{
  int s;
  long int ans[2001]={0,0,0,1};

  scanf("%d",&s);

  for(int i=4;i<=s;i++)
  {
    ans[i]=(ans[i-1]+ans[i-3])%(1000000007);
  }

  printf("%ld\n",ans[s]);

  return 0;
}

Measured memory_bytes: 1748
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

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

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

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

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

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

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

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

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

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

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	fmt.Println(pow(N, 3))
}


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

constexpr long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int main(){
  int k;
  cin >> k;
  int a = k / 100;
  int b = k % 100;
  bool fa = 0, fb = 0;
  if (1 <= a && a <= 12) {
    fa = 1;
  }
  if (1 <= b && b <= 12) {
    fb = 1;
  }
  if (fa && fb) {
    cout << "AMBIGUOUS" << endl;
  } else if (fa) cout << "MMYY" << endl;
  else if (fb) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  return 0;
}


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

long long cnt;
long l;
long A[1000000];
long n;
vector<long> G;

void insertionSort(long A[], long n, long g){
	for (long i = g; i < n; i++){
		long v = A[i];
		long j = i - g;
		while ( j >= 0 && A[j] > v){
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(long A[], long n){
	for (long h = 1; ; ){
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (long i = G.size() - 1; i >= 0; i--) insertionSort(A, n, G[i]);
}

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

	shellSort(A, n);

	cout << G.size() << endl;
	for (long i = G.size() - 1; i >= 0; i--){
		cout << G[i];
		if (i) cout << " ";
	}
	cout << endl;
	cout << cnt << endl;
	for (long i = 0; i < n; i++) cout << A[i] << endl;

	return 0;
}

Measured memory_bytes: 9028
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11;
int n, k, ans;
int main(){
    cin>>n>>k;
    int h;
    for(int i = 1;i <= n; i++){
        scanf("%d", &h);
        if(h >= k)ans++;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////


int main() {

	ll N;
	string s[MAX];
	ll t[MAX];
	string X;
	cin >> N;
	repn(i, N) cin >> s[i] >> t[i];
	cin >> X;

	ll ans = 0;

	bool b = 0;

	repn(i, N) {
		if (s[i] == X) { b = 1; }
		else if (b == 1) { ans += t[i]; }
	}

	cout << ans;

	


	system("PAUSE");


}


Measured memory_bytes: 10232
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n), suma(n+1, 0), sumb(n+1, 0);
  rep(i, n) {
    cin >> a[i];
    suma[i+1] += suma[i] + a[i];
  }
  rep(i, n) {
    cin >> b[i];
    sumb[i+1] += sumb[i] + b[i];
  }

  ll ans = -1;
  for (int i = 1; i < n+1; ++i) {
    ll tmpa = suma[i], tmpb = sumb[n] - sumb[i-1];
    chmax(ans, tmpa + tmpb);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
N, M = [int(x) for x in input().split()]

s = []; e = [];
s.append(1)
e.append(2 * -(-M // 2)) # 2 * ceiling(M/2)
s.append(N - 2 * (M // 2))
e.append(N)

n = 0
while True:
    for i in range(2):
        if n >= M: sys.exit()
        print(s[i], e[i])
        s[i] += 1
        e[i] -= 1
        n += 1

Measured memory_bytes: 9284
#include <iostream>

#define mod 1000000007
using namespace std;
long long dp[3010][3010][2];
int main(){
	int i,j,n,m;
	cin >> n >> m;
	for(i=0;i<=n;i++){
		for(j=0;j<=m;j++){
			dp[i][j][0] = 0;
			dp[i][j][1] = 0;
		}
	}
	
	for(i=1;i<=n;i++){
		dp[i][0][0] = 1;
	}
	dp[0][0][1] = 1;
	
	for(j=0;j<m;j++){
		for(i=0;i<=n;i++){
			if(i==0){
				dp[i][j+1][1] += dp[i][j][1];
			}else if(i==1){
				dp[i-1][j+1][1] += dp[i][j][0] + dp[i][j][1];
				dp[i][j+1][1] += dp[i][j][1];
				dp[i][j+1][0] += dp[i][j][0];
			}else if(i>=2 && i<=n-1){
				dp[i-1][j+1][0] += dp[i][j][0];
				dp[i][j+1][0] += dp[i][j][0];
				dp[i-1][j+1][1] += dp[i][j][1];
				dp[i][j+1][1] += dp[i][j][1];
			}else if(i==n){
				dp[i-1][j+1][0] += dp[i][j][0];
				dp[i-1][j+1][1] += dp[i][j][1];
			}
			if(i>=1){
				dp[i-1][j+1][0] %= mod;
				dp[i-1][j+1][1] %= mod;
			}
			dp[i][j+1][0] %= mod;
			dp[i][j+1][1] %= mod;
		}
		for(i=n;i>=1;i--){
			dp[i][j][0] = dp[i-1][j+1][0];
			dp[i-1][j+1][0] = 0;
			dp[i][j][1] = dp[i-1][j+1][1];
			dp[i-1][j+1][1] = 0;
		}
		dp[n][j+1][0] = 0; dp[n][j+1][1] = 0;
		for(i=1;i<=n;i++){
			if(i==1){
				dp[i-1][j+1][1] += dp[i][j][0] + dp[i][j][1];
				dp[i][j+1][1] += dp[i][j][1];
				dp[i][j+1][0] += dp[i][j][0];
			}else{
				dp[i-1][j+1][0] += dp[i][j][0];
				dp[i][j+1][0] += dp[i][j][0];
				dp[i-1][j+1][1] += dp[i][j][1];
				dp[i][j+1][1] += dp[i][j][1];
			}
			if(i>=1){
				dp[i-1][j+1][0] %= mod;
				dp[i-1][j+1][1] %= mod;
			}
			dp[i][j+1][0] %= mod;
			dp[i][j+1][1] %= mod;
		}
	}
	
	long long ans = 0;
	for(i=0;i<=n;i++){
		ans += dp[i][m][1];
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 141568
n,m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort.reverse
map = [0,2,5,5,4,5,6,3,7,6]
dp = Array.new(n+1,0)
a.each do |x|
  dp[map[x]] = 1
end
1.upto(n) do |i|
  a.each do |x|
    if i-map[x] >= 0
      dp[i] = [dp[i-map[x]]+1,dp[i]].max if dp[i-map[x]] != 0
    end
  end
end
cnt = n
ans = []
dp[n].times do |i|
  a.each do |x|
    if dp[cnt-map[x]] == dp[cnt] - 1
      if i != dp[n]-1 || cnt-map[x] == 0
        ans << x
        cnt -= map[x]
        break
      end
    end
  end
end
ans.each do |x|
  print x
end
puts ""

Measured memory_bytes: 14412
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define LL long long
LL mod = 1000000007;
char S[4][54];
LL ans = 1;
int N;
int main() {
	std::cin >> N;
	for (int i = 1; i < 3; i++) {
		for (int j = 1; j <= N; j++) {
			std::cin >> S[i][j];
		}
	} 
	bool mode = true;
	int st;
	if (S[1][1] == S[2][1]) {
		ans *= 3;
		st = 2;
	}
	else {
		mode = false;
		ans *= 6;
		st = 3;
	}
	for (int i = st; i <= N; i++) {
		if (mode) {
			if (S[1][i] == S[2][i])ans *= 2;
			else {
				i++;
				mode = false;
				ans *= 2;
			}
		}
		else {
			if (S[1][i] == S[2][i]) {
				mode = true;
			}
			else {
				i++;
				ans *= 3;
			}
		}
		ans %= mod;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
var lines = []; var result = Infinity;
var readline = require('readline');


var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    if (Number(lines[0]) === 1) { console.log("Hello World"); }
    else{
        console.log(Number(lines[1]) + Number(lines[2]));
    }
});

Measured memory_bytes: 7500
#include<stdio.h>
int main(void)
{
	int n,p[1001][4],i,j,kijyun[1001]={0},sum[1001]={0},k,re[1001];
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    for(j=0;j<3;j++){
	        scanf("%d",&p[i][j]);
	    }
	}
	for(j=0;j<3;j++){
	    for(i=0;i<n;i++){
	        kijyun[i]=p[i][j];
	        for(k=0;k<n;k++){
	            if(i!=k){
	                if(kijyun[i]==p[k][j]){
	                    p[k][j]=0;
	                    p[i][j]=0;
	                }
	            }
	        }
	    }
	    for(k=0;k<n;k++){
	        sum[k]=sum[k]+p[k][j];
	    }
	} 
		for(k=0;k<n;k++){
	    printf("%d\n",sum[k]);
	}
	return 0;
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int one = 0, two = 0, four = 0;
  cin >> n;
  int num;
  for(int i = 0; i < n; i++) {
    scanf("%d", &num);
    if(num % 4 == 0) four++;
    else if(num % 2 == 0) two++;
    else one++;
  }
  if(two > 0) {
    if(four >= one) printf("Yes\n");
    else printf("No\n");
  } else {
    if(four+1 >= one) printf("Yes\n");
    else printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 (ll)1 << 60
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, m, f[110000], ans = 1, now;
vector<ll> s;
ll po(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}

ll com(ll n, ll r) {
	return f[n] * po(f[r] * f[n - r], 1e9 + 5) % MOD;
}

int main() {
	f[0] = 1;
	REP(i, 101010)f[i + 1] = f[i] * (i + 1) % MOD;
	cin >> n >> m;
	now = m;
	for (ll i = 2; i <= sqrt(m); i++)
	{
		if (m % i == 0) {
			ll st = 0;
			while (now % i == 0) {
				st++;
				now /= i;
			}
			s.push_back(st);
		}
	}
	if (now > 1)s.push_back(1);
	REP(i, s.size()) {
		ans *= com(s[i] + n - 1, s[i]);
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
    string W;
    bool flg = true;
    cin >> W;
    int array[26] = {0};
    if(W.length() % 2 == 0){
        for(int i = 0; i < W.length(); i++){
            array[W[i] - 'a'] += 1;
        }
        for(int i = 0; i < 26; i++){
            if(array[i] % 2 != 0){
                flg = false;
                break;
            }
        }
    }
    else{
        flg = false;
    }

    if(flg){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

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

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

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

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

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a;
	long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	double judge = sum * 1.0 / (4 * m);
	for (int i = 0; i < m; i++)
	{
		if (a[i] < judge)
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 31488
s = str(input())
n = len(s)
x = [0]*2019
x[0] = 1
m = 0
j = 1
for i in range(n):
  m = (m + int(s[-i-1])*j)%2019
  x[m] += 1
  j = (j*10)%2019
ans = 0
for i in range(2019):
  ans += (x[i]*(x[i]-1))//2
print(ans)


Measured memory_bytes: 68300
while True:
    s, cc = input().split()
    if cc == "X":break
    if "_" in s:
        t = s.split("_")
    else:
        t = []
        j = 0
        for i in range(1, len(s)):
            if s[i].isupper():
                t.append(s[j:i])
                j = i
        t.append(s[j:])
    if cc == "U":
        for i in range(len(t)):t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    elif cc == "L":
        t[0] = t[0].lower()
        for i in range(1, len(t)):t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    else:
        for i in range(len(t)):t[i] = t[i].lower()
        print("_".join(t))


Measured memory_bytes: 5564
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
typedef long long ll;
ll n,k,dp[maxn][10],sum[maxn][10],tot,sum2[maxn][10];
char t[maxn];
int main() {
	for (int j = 0; j <= 9; j++)
		dp[1][j] = 1;
	for (int i = 2; i <= 18; i++) {
		for (int j = 0; j <= 9; j++) {
			dp[i][j] += dp[i - 1][j];
			if (j < 9) dp[i][j] += dp[i - 1][j + 1];
			if (j > 0) dp[i][j] += dp[i - 1][j - 1];
		}
	}
	for (int i = 1; i <= 18; i++) {
		sum[i][0] = sum[i - 1][9];
		sum[1][0] = 1;
		for (int j = 1; j <= 9; j++) {
			sum[i][j] = sum[i - 1][9];
			for (int k = 1; k <= j; k++)
				sum[i][j] += dp[i][k];
		}
		for (int j = 0; j <= 9; j++) {
			sum2[i][j] = sum2[i - 1][9];
			for (int k = 0; k <= j; k++)
				sum2[i][j] += dp[i][k];
		}
	}
	//printf("%lld\n",sum[2][1]);
	scanf("%lld",&k);
	int p = 0;
	for (int i = 18; i >= 0; i--) {
		if (sum[i][9] < k) {
			p = i + 1;
			break;
		}
	}
	bool limit = true;
	for (int i = p; i >= 1; i--) {
		if (limit) {
			for (int j = 1; j <= 9; j++) {
				if (sum[i][j] >= k) {
					t[++tot] = j + '0';
					k -= sum[i][j - 1];
					limit = false;
					break;
				}
			}
		} else {
			for (int j = max(0,t[tot] - '0' - 1); j <= t[tot] - '0' + 1; j++) {
				int tmp = t[tot] - '0' - 2;
				if (dp[i][j]  < k) {
					k -= dp[i][j];
				} else {
					t[++tot] = j + '0';
					break;
				}
			}			
		}
	}
	t[++tot] = 0;
	printf("%s\n",t + 1);
	return 0;
}

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

int main() {
  long int N, K, a, b, Answer = 0, sum[SUM_LIMIT] = {0}, i;
  cin >> N >> K;
  for (i = 0; i < N; i++) {
    cin >> a >> b;
    sum[a] += b;
  }
  for (i = 0; K > 0; i++) {
    K -= sum[i];
  }
  cout << i - 1 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}

void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}

graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}

void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}

int main() {
    ll N,M;
    cin >> N >> M;
    auto A = InputVec2dStr(N,N);
    auto B = InputVec2dStr(M,M);
    for (int yi = 0; yi < N -M + 1; ++yi) {
        for (int xi = 0; xi < N-M + 1; ++xi) {
            bool judge = true;
            for (int qi = 0; qi < M; ++qi) {
                for (int pi = 0; pi < M; ++pi) {
                    if(A[yi + qi][xi + pi] != B[qi][pi]){
                        judge = false;
                    }
                }
                if(!judge){
                    break;
                }
            }
            if(judge){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
master_streets = []
for i in 0..2 do
  master_streets.push(gets.chomp.split(" ").map(&:to_i))
end

travel_flag = true
master_streets.flatten.sort.each{ |street|
  count =0
  master_streets.flatten.sort.each{ |comp_street|
    count += 1 if  street == comp_street
  }
  if count > 2
    travel_flag = false
  end
}
if travel_flag
  print("YES\n")
else
  print("NO\n")
end

Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    int count = 0;
    cin >> n >> m;
    vector<int> food(m);
    rep(i, n) {
      int k;
      cin >> k;
      rep(j, k) {
        int num;
        cin >> num;
        food[num - 1]++;
      }
    }
    rep(i, m) {
      if (food[i] == n) {
        ++count;
      }
    }

    cout << count << '\n';

    return 0;
}


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

int main(){
    vector<string> g = {"SAT","SUN","MON","TUE","WED","THU","FRI","SAT","SUN","MON","TUE","WED","THU","FRI"};
    string s;
    cin >> s;
    for(int i = 0 ; i < 7 ; i += 1){
        if(s == g[i]){
            for(int j = i+1 ; j < 14 ; j += 1){
                if(g[j] == "SUN"){
                    cout << j-i;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a = set([int(input()) for _ in range(m)])

INF=1000000007
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        continue
    dp[i]=dp[i-1]+dp[i-2]
    dp[i]%=INF
print(dp[n])



Measured memory_bytes: 13216
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> a(n+1,2);
  a[1] = 1;
  for (ll i = 2; i <= n/2; i++) {
    for (ll j = 2; j*i <= n; j++) {
      a[i*j]++;
    }
  }
  rep(i,n) {
    ans += a[i+1] * (i+1);
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed <<"ms"<< '\n';
}

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

int main(){

    int a,b,comp;

    scanf("%d %d",&a,&b);

    if(a==1)
        a=14;
    if(b==1)
        b=14;

    if(a>b){
        printf("Alice\n");
    }else if(b>a){
        printf("Bob\n");
    }else printf("Draw\n");


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  set<string> st;
  int n = in();
  rep(i,n) {
    st.insert(stin());
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 19320
#include <stdio.h>
long long min(long long n,long long m){
    if(n<m) return n;
    else return m;
}
int main(void){
    long long n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    printf("%lld",(n/(a+b))*a+min(a,n%(a+b)));
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	
	int a, b, c;
    
    scanf("%d", &a);
    scanf("%d%d", &b, &c);
    
 	int d = b%a;
  	if(d == 0){
       printf("OK");
       return 0;
    }
  	if(b-d+a > c){
    	printf("NG");
      	return 0;
    }
       
    printf("OK");
    return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
a^2 = b^2 + c^2 - 2bc conA

*/
double PI = acos(-1);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll A, B, H, M; cin >> A >> B >> H >> M;
  double ans;
  double m;
  double h;
  m = 6 * M;
  h = 30 * H;
  h += 0.50 * M;
  double theta = abs(m-h);
  if (theta > 180)
    theta = 360 - theta;
//  cout<<theta<<endl;
  theta /= 180.0;
  theta *= PI;
  ans = A*A + B*B - 2 * A * B * cos(theta);
  ans = sqrt(ans);
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 4112
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

from collections import defaultdict
g = defaultdict(list)
for a, b in ab:
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

k = 0
for key in g:
    k = max(k, len(g[key]))
print(k)

ans = dict()
q = [(0, -1)] # (pos, used_color)
visited = set([0])
while q:
    cur, col = q.pop()

    if col == 0:
        tmp = 1
    else:
        tmp = 0

    for target in g[cur]:
        if target not in visited:
            q.append((target, tmp))
            visited.add(target)
            ans[(cur, target)] = tmp

            if tmp + 1 == col:
                tmp += 2
            else:
                tmp += 1

for a, b in ab:
    key = (a-1, b-1)
    print(ans[key] + 1)


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

int main(){
    int c[3][3];
    int x[3][3];
    int y[3][3];
    bool p = 0;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
            x[i][j] = y[i][j] = c[i][j];
        }
    }
    
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            x[i][j] -= c[(i+1) % 3][j];
        }
        if(x[i][1] == x[i][2] && x[i][0] == x[i][2]){
            p = 1;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 0; i <3; i++){
        for(int j = 0; j < 3; j++){
            y[j][i] -= c[j][(i+1) % 3];
        }
        if(y[0][i] == y[1][i] && y[0][i] == y[2][i]){
            p = 1;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int n,sum=0;
	cin>>n;
	int a[n+1];
	
	a[0]=0X7fffffff,a[n]=0X7fffffff;
	for(int i=1;i<n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		sum+=min(a[i-1],a[i]);
	}
	cout<<sum;
}


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

int main()
{
  	int a, b, c;
  cin >> a >> b >> c;
  
  if (a==b && b==c) cout << 1 << endl;
  else if (a!=b && b!=c && c!=a) cout << 3 << endl;
  else cout << 2 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 768
s = input()

c = -1
ans = []
for i in range(len(s)):
   if (s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T'):
      if (c < 0):
         c = i
   else:
      if (c >= 0):
         ans.append(i - c)
         c = -1

if (c >= 0):
   ans.append(len(s) - c)
try:
   print(max(ans))
except:
   print(0)


Measured memory_bytes: 3060
N=input()
LL=[]
def find(s):
    count=0
    for i in xrange(len(s)-1):
        if s[i]+s[i+1]=='AB':
            count+=1
    return count        
 
ans=0
start_B=0
end_A=0
same_time=0
for i in xrange(N):
    s=raw_input()
    ans+=find(s)
    if s[-1]=='A':
        end_A+=1
    if s[0]=='B':
        start_B+=1   
    if s[0]=='B' and s[-1]=='A':
        same_time+=1
 
 
#print(ans,end_A,start_B,same_time)
final=ans+min(end_A-same_time,start_B-same_time)
if end_A!=start_B:
    print(final+same_time)
else:
    if end_A-same_time>0:
        print(final+max(same_time,0))
    else:
        print(final+max(same_time-1,0))


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

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;

ll a[MAXN];
int main()
{
    int n,t;
    cin>>n>>t;
    for(int i = 1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll differ = 0ll;
    ll cnt = 0ll;
    ll most =1e18+8;
    for(int i = 1; i<= n;i++)
    {
        if( differ < a[i]-most)
        {
            differ = a[i]-most;
            cnt = 1;
        }
        else if(differ == a[i]-most)
        {
            cnt++;
        }
        most = min(most,a[i]);
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

// 0-indexed bottom up Segment Tree
// UNIT is the identity element of operation func
template <typename T = int>
struct SegmentTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> dat;
    F func;
    T UNIT;

    SegmentTree(int n_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        // full binary tree: num of leaves = n = 2^k >= n_
        while (n < n_)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
    }
    SegmentTree(vector<T> v_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n      = 1;
        int nv = v_.size();
        while (n < nv)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
        for (int i = 0; i < nv; ++i) {
            dat[n - 1 + i] = v_[i];
        }
        for (int i = n - 2; i >= 0; --i) {
            dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }
    void update(int k, T a) {
        // leaves are at index n-1 to 2*n-2
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            // k -> parent node
            k = (k - 1) / 2;
            // func(child nodes)
            dat[k] = func(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    // get result of func() in [l, r)
    T query(int l, int r) {
        l += n - 1;
        r += n - 1;
        T retl = UNIT, retr = UNIT;
        while (l < r) {
            if ((l & 1) == 0)
                retl = func(retl, dat[l]);
            if ((r & 1) == 0)
                retr = func(dat[r - 1], retr);
            l = l / 2;
            r = (r - 1) / 2;
        }
        return func(retl, retr);
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    string s;
    cin >> s;
    lint m = 1 << n;
    vector<lint> p(1 << (n));
    vector<vector<lint>> dp(n + 10, vector<lint>(1 << (n + 2), -1));
    for (int i = 0; i < (1 << n); ++i) {
        cin >> p[i];
        dp[0][i] = dp[0][i + m] = p[i];
    }
    const lint unit = -1;
    auto f          = [&](lint l, lint r) {
        if (l == unit)
            return r;
        if (r == unit)
            return l;
        if (l > r)
            swap(l, r);
        if (s[r - l - 1] == '1')
            return r;
        else
            return l;
    };
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 2 * m; ++j) {
            dp[i][j] = f(dp[i - 1][j], dp[i - 1][(j + (1 << (i - 1))) % m]);
        }
    }
    for (int i = 0; i < m; ++i) {
        cout << dp[n][i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 243124
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846

int main(){
    ll H,W;
    cin >> H >> W;
    bool bord[52][52] = {0};
    REP(i,H){
        REP(j,W){
            char s;
            cin >> s;
            if(s=='#') bord[i+1][j+1]=1;
        }
    }
    REP(i,H){
        REP(j,W){
            if(!(bord[i+1][j+1]))continue;
            if(bord[i][j+1])continue;
            if(bord[i+1][j])continue;
            if(bord[i+2][j+1])continue;
            if(bord[i+1][j+2])continue;
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, M;
    cin >> N >> M;
    vector<ll> balls(N, 1);
    vector<ll> pos(N, 0);
    pos[0] = 1;
    REP(i, M){
    	ll x, y;
    	cin >> x >> y;
    	x--;y--;
    	balls[x]--;
    	balls[y]++;
    	if(pos[x] == 1){
    		pos[y] = 1;
    		if(balls[x] == 0){
    			pos[x] = 0;
    		}
    	}
    }
    //cout << pos << endl;
    ll res = 0;
    REP(i, N) res += pos[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
// Marcin Knapik
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< int , null_type,less< int >, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ll>(a, b)(rng)

#define int ll
typedef long double             ld;
typedef long long               ll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<vll>             vvll;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vii>             vvii;
#define pll pair<long long, long long>
#define ull unsigned long long

#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<class T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return abs(a); }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll N = 1e6+7;
const ll T = 1<<20;
const ld inf = 1e18;

ll m, n, k, q;

int solve(string & s, int below){
	vi pref = {0};
	for(int i = 0; i < sz(s); i++)
		pref.pb(pref.back() + (s[i] == '0' ? -1 : 1));

	vi min_suf = pref;
	for(int i = sz(s) - 1; i >= 0; i--)
		min_suf[i] = min(min_suf[i + 1], pref[i]);
		
	int dod = 0, maxi = 0;

	for(int i = 1; i <= sz(s); i++){
		if(s[i - 1] == '?' and min_suf[i] - dod - 2 >= min_suf[0] - below)
			dod += 2;
		maxi = max(maxi, pref[i] - dod);
	}

	return maxi - (min_suf[0] - below);
}

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

	string s;
	cin >> s;
	cout << min(solve(s, 0), solve(s, 1)) << '\n'; 
}

Measured memory_bytes: 20288
import sys
input = sys.stdin.readline
from collections import *

def f(ma, mb):
    if ma==mb:
        return 1
        
    m = N//2
    mad = int(ma)
    mau = mad+1
    mbd = int(mb)
    mbu = mbd+1
    
    if str(ma)[-1]=='5' and str(mb)[-1]=='5':
        return mbu-mad+1
    elif str(ma)[-1]=='5':
        return mbd-mad+1
    elif str(mb)[-1]=='5':
        return mbu-mad+1
    else:
        return mbd-mad+1

N = int(input())
A, B = [], []

for _ in range(N):
    Ai, Bi = map(int, input().split())
    A.append(Ai)
    B.append(Bi)

A.sort()
B.sort()

if N%2==1:
    ma = A[N//2]
    mb = B[N//2]
    print(mb-ma+1)
else:
    m = N//2
    ma = (A[m-1]+A[m])/2
    mb = (B[m-1]+B[m])/2
    print(int(2*mb-2*ma+1))

Measured memory_bytes: 91116
def main():
  n, m, q = map(int, input().split() )
  a = [0] * q
  b = [0] * q
  c = [0] * q
  d = [0] * q
  for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split() )
  A = [1] * (n + 1)
  A[0] = 0
  ans = 0
  while A[0]==0:
    tmp = 0
    for i in range(q):
      if( A[b[i]]-A[a[i]]==c[i] ):
        tmp += d[i]
    ans = max(ans, tmp)
    A[n] += 1
    for i in range(1,n+1):
      if( A[i]>m ):
        i-=1
        A[i] += 1
        t = A[i]
        for j in range(i,n+1):
          A[j] = t
        break
  print(ans)

main()

Measured memory_bytes: 9256