akhauriyash/Code-Regression huggingface dataset:
n,k,q = gets.split(' ').map(&:to_i)
ary = []
q.times { ary << gets.to_i }

ans = [0] * n
ary.each do |a|
  ans[a-1] += 1
end

ans.each do |a|
  if a > q - k 
    puts 'Yes'
  else
    puts 'No'
  end
end

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  vector<vector<int>> mp(h, vector<int>(w));
  for (int i = 0; i < h - b; i++) for (int j = 0; j < w - a; j++) mp[i][j] = 1;
  for (int i = h - b; i < h; i++) for (int j = w - a; j < w; j++) mp[i][j] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cout << mp[i][j];
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 5248
n = int(input())
dat = list(map(int, input().split()))
mode = 0 #  0: None, 1: add, 2: sub
res = 1
for i in range(1, n):
    if mode == 0:
        if dat[i-1] == dat[i]:
            mode = 0
        if dat[i-1] > dat[i]:
            mode = 2
        if dat[i-1] < dat[i]:
            mode = 1
    if mode == 1:
        if dat[i-1] == dat[i]:
            pass
        if dat[i-1] > dat[i]:
            res += 1
            mode = 0
        if dat[i-1] < dat[i]:
            pass
    if mode == 2:
        if dat[i-1] == dat[i]:
            pass
        if dat[i-1] > dat[i]:
            pass
        if dat[i-1] < dat[i]:
            res += 1
            mode = 0
print(res)

Measured memory_bytes: 14480
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int lli;
void solve(){
    string ans = "";
    string s1, s2;
    cin >> s1 >> s2;
    lli n = s1.size();
    for(lli i = 0; i < n; i++){
        ans += s1[i];
    }
    cout << ans << endl;
}
int main(){
    //freopen("input.txt","r",stdin);
    fastio
    lli x, y;
    vector <lli> arr(3);
    cin >> x;
    arr[x - 1] = 1;
    cin >> y;
    arr[y - 1] = 1;
    for(lli i = 0; i < 3; i++){
        if(arr[i] == 0){
            cout << i + 1 << endl;
            return 0;
        }
    }

    return 0;
}




Measured memory_bytes: 256
<?php
$count = 0;
fscanf(STDIN, "%d", $n);

flush();
echo 0,"\n";
fscanf(STDIN, "%s", $s);
$count ++;

if ($s == "Vacant") {
	die();
}
check(0, $n, $s, $count);

function check($start, $end, $beforeS, $count) {
	$k = floor(($end - $start) / 2);
	$point = $k + $start;
	flush();
	echo $point,"\n";
	fscanf(STDIN, "%s", $s);
	$count ++;
	if ($count > 20) {
		die();
	}

	if ($s == "Vacant") {
		die();
	}
	if ($k % 2 === 0) {
		if ($beforeS === $s) {
			return check($point, $end, $s, $count);
		}
		return check($start, $point, $beforeS, $count);
	}
	if ($beforeS !== $s) {
		return check($point, $end, $s, $count);
	}
	return check($start, $point, $beforeS, $count);
}


Measured memory_bytes: 5200
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <utility>
#include <cmath>

using namespace std;

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

#define INF 		2000000007
#define MOD			998244353
#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

vector<vector<int> > s(12,vector<int>(12,0));

int main(){
	int N,M;cin>>N>>M;
	vector<int> P(M);
	vector<int> k(M);

	REP(i,M){
		cin>>k[i];
		REP(j,k[i]){
			cin >>s[i][j];
			s[i][j] = (int)pow(2,s[i][j]-1);
		}
	}
	REP(i,M)cin>>P[i];

	int cnt = 0;

	for(int i=1,i_end=(int)pow(2,N)+1;i < i_end;++i){
		bool flag = true;
		REP(j,M){
			int suml=0;
			REP(l,k[j]){
				if(s[j][l]&i)suml++;
			}
			if((suml%2)!=P[j])flag = false;
		}
		if(flag)cnt++;
	}//*/

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

struct N {
  int n, d;
};

bool operator<(const N &l, const N &r) { return l.d < r.d; }

int main() {
  int k;
  cin >> k;
  multiset<N> q;
  q.insert(N{1, 1});
  bool used[102020] = {0};
  while (q.size() > 0) {
    N now = *q.begin();
    q.erase(q.begin());
    if (now.n == 0) {
      cout << now.d << endl;
      return 0;
    }
    if (used[now.n])
      continue;
    used[now.n] = true;
    if (!used[(now.n + 1) % k])
      q.insert(N{(now.n + 1) % k, now.d + 1});
    if (!used[(now.n * 10) % k])
      q.insert(N{(now.n * 10) % k, now.d});
  }

  return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
ll memo[1<<20];
ll fibo(int n){
  if (n == 0) return 2;
  if(n ==1) return 1;
  if(memo[n]!=0) return memo[n];
  return  memo[n] = fibo(n-1)+fibo(n-2);
}

int main(){
     int n;
     cin >> n;
    cout << fibo(n)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();           //コマの数
        int[] X = new int[N];           //各コマの止まっているマス
        for(int i = 0; i < N; i++){
            X[i] = sc.nextInt();
        }
        int M =sc.nextInt();            //移動する回数
        for(int i = 0; i < M; i++){
            int A = sc.nextInt() - 1;   //今回移動を行うコマ番号
            boolean stayFlag = false;
            for(int n = 0; n < N; n++){
                if(n == A) continue;    //同じコマ同士は比較しない
                if((X[A] == 2019) || ((X[A] + 1) == X[n])) stayFlag = true; //止まっているマスがゴール、もしくは隣のマスに他のコマが止まっていたら移動しない
            }
            if(!stayFlag) X[A]++;   //とどまるフラグが立っていなければ１マス進む
        }
        for(int i = 0; i < N; i++){
            System.out.println(X[i]);
        }
    }
}



Measured memory_bytes: 26484
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{

    char s[5];
    while(cin>>s[0]>>s[1]>>s[2]>>s[3]>>s[4]>>s[5])
    {
        if(s[2]==s[3] && s[4]==s[5])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(x) begin(x), end(x)

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int h, w, k; cin >> h >> w >> k;
	vector<string> v(h);
	for (int i = 0; i < h; ++i)
	{
		cin >> v[i];
	}
	vector<vector<int>> ans(h);
	int ct = 1;
	int up = 0;
	for (int i = 0; i < h; ++i)
	{
		vector<int> temp(w, 0);
		ans[i] = temp;
	}
	for (int i = 0; i < h; ++i)
	{
		bool flag = 0;
		int prev = 0;
		for (int j = 0; j < w; ++j)
		{
			if (v[i][j] == '#')
			{
				flag = 1;
				for (int x = up; x <= i; ++x)
					for (int y = prev; y <= j; ++y)
						ans[x][y] = ct;
				++ct;
				prev = j+1;
			}
		}
		if (flag)
		{
			for (int x = up; x <= i; ++x)
				for (int j = prev; j < w; ++j)
					ans[x][j] = ans[x][prev-1];
			up = i + 1;
		}
	}
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
		{
			if (ans[i][j] == 0)
			{
				assert(i > 0);
				ans[i][j] = ans[i-1][j];
			}
			cout << ans[i][j] << " \n"[j == w-1];
		}
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		double R = scanner.nextDouble();

		double answer = 2 * R * Math.PI;

		System.out.println(answer);

		scanner.close();

	}
}

Measured memory_bytes: 28856
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
const int max_v = 10100;
const int max_e = 505000;
const int inf = 0x3fffffff;

typedef pair<int, int> P;

typedef struct edge {
    int to, dist;
    edge():to(0),dist(0) {}
    edge(int _to, int _dist):to(_to),dist(_dist) {}
    bool operator < (const edge & o) const {
	return dist > o.dist;
    }
}edge;

struct graph {
    int V, E;
    int d[max_v], prev[max_v];
    bool vis[max_v];
    vector<edge> G[max_v];
    graph():V(0),E(0) {}

    graph(int _V):V(_V),E(0) {}

    graph(int _V, int _E, int ed[][3], bool bidirect):V(_V),E(_E) {
	rep(i, E) {
	    int u = ed[i][0], v = ed[i][1], dist = ed[i][2];
	    G[u].push_back(edge(v, dist));
	    if (bidirect) G[v].push_back(edge(v, dist));
	}
    }
    graph(int _V, int g[][max_v]) {
	V = _V; E = 0;
	rep(i, V) rep(j, V)
	    if (g[i][j] != inf) {
		G[i].push_back(edge(j, g[i][j]));
		++E;
	    }
    }

    void add_edge(int u, int v, int c) {
	G[u].push_back(edge(v, c));
    }

    void output() {
	rep(i, V) {
	    printf("[%d] ", i);
	    rep(j, G[i].size()) {
		printf("(%d %d) ", G[i][j].to, G[i][j].dist);
	    }
	    putchar('\n');
	}
    }

    void dijkstra(int g[][max_v], int s) {
	rep(i, V) d[i] = inf;
	rep(i, V) prev[i] = -1;
	rep(i, V) vis[i] = false;

	d[s] = 0;
	rep(i, V) {
	    int tmp = inf;
	    int u = -1;
	    rep(j, V) {
		if(!vis[j] && d[j] < tmp) {
		    tmp = d[j];
		    u = j;
		}
	    }
	    vis[u] = true;
	    rep(j, V) {
		if(!vis[j] && d[u] + g[u][j] < d[j]) {
		    d[j] = d[u] + g[u][j];
		    prev[j] = u;
		}
	    }
	}
    }

    void dijkstra(int s) {
	rep(i, V) d[i] = inf;
	rep(i, V) prev[i] = -1;
	rep(i, V) vis[i] = false;
	
	priority_queue<edge> pq;
	pq.push(edge(s, 0));
	d[s] = 0;

	while(! pq.empty()) {
	    edge e = pq.top(); pq.pop();
	    if(e.dist > d[e.to]) continue;
	    d[e.to] = e.dist;
	    vis[e.to] = true;
	    
	    rep(j, G[e.to].size()) {
		int v = G[e.to][j].to;
		int dist = G[e.to][j].dist;

		if(!vis[v] && d[e.to] + dist < d[v]) {
		    d[v] = d[e.to] + dist;
		    prev[v] = e.to;
		    pq.push(edge(v, d[v]));
		}
	    }
	}
    }
};

int N, M;

void solve() {
    int u, k, v, c;
    scanf("%d", &N);
    graph g = graph(N);
    rep(i, N) {
	scanf("%d%d", &u, &k);
	rep(j, k) {
	    scanf("%d%d", &v, &c);
	    g.add_edge(u, v, c);
	}
    }
    g.dijkstra(0);
    rep(i, N) {
	printf("%d %d\n", i, g.d[i]);
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 6288
#include <iostream>
#include <stdlib.h>
using namespace std;
int comp(const void *value1, const void *value2){
    return *(const int *)value1 - *(const int *)value2;
}
int main() {
  int height[10];
  for(int i=0; i<10; i++) cin >> height[i];
  qsort(height, 10, sizeof(int), comp);
  cout << height[9] << "\n" << height[8] << "\n" << height[7] << endl;
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	if (k == 0) {
		cout << n*n << endl;
		return 0;
	}
	for (int b = k + 1; b <= n; b++) {
		ans += k * ((n + 1) / b);
		//DEBUG(ans);
		ans += min((n + 1) % b, k);
		//DEBUG(ans);
	}
	cout << (n - k) * (n + 1) - ans << endl;

}


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

int A,B,N;

signed main() {
  cin >> A >> B >> N;
  int x = min(N, B-1);
  int l = floor(A*x / (double)B);
  int r = A * floor(x / (double)B);
  cout << l-r << endl;
}



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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9 + 7;

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

int N;

int main() {
  scanf("%d", &N);
  vector<double> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lf", &p[i]);
  }

  vector<double> dp(N + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j >= 1; j--) {
      dp[j] = (1 - p[i]) * dp[j] + p[i] * dp[j - 1];
    }
    dp[0] = (1 - p[i]) * dp[0];
  }

  double ans = 0;
  for (int j = N / 2 + 1; j <= N; j++) {
    ans += dp[j];
  }
  
  printf("%.10lf\n", ans);
}


Measured memory_bytes: 384
#include<stdio.h>
 
int main()
{
    char ch[3];
    int i = 0,count = 0,len=0;
    gets(ch);
    len = strlen(ch);
    
    while(len--) {
        if(ch[i]=='o')count++;
         i++;
    }
    printf("%d\n", (700+(count*100)));
    return 0;
}

Measured memory_bytes: 128
"use strict"

function main(input){
  const args=input.split("\n");
  const N=parseInt(args[0],10);

  //花の高さh1, h2, …を入れた配列
  const heights=input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
  const Max=Math.max.apply(null, heights);

  var checkFunc = function ( value, index, sourceArray ) {
    if(value==0){
      return true
    }else{
      return false
    }
  }

  if(heights.every(checkFunc)==true){
    console.log(0);
  }else{
    //特定の高さにおけるチャンク数を計算して配列に入れる
  var changArr=[];
  for(var i=1; i<=Max; i++){
    //高さiにおける花の数
    var hananoKazu=heights.filter(function(a){return(a>=i)}).length;
    //高さi以上の花それぞれ、「その1つ後にも高さi以上の花が存在する」場合にマイナス処理
    for(var j=0; j<N; j++){
      if(heights[j]>=i && heights[j+1]>=i){
        hananoKazu--
      }
    }
    //それをしてできた値が「高さiにおけるチャンクの数」である。
    changArr.push(hananoKazu);
  }
  //console.log(changArr);
  
  var setsuyakuKaisuu=[];
  for(var i=1; i<=Max; i++){
    var hananoKazu=heights.filter(function(a){return(a>=i)}).length;
    setsuyakuKaisuu.push(hananoKazu-changArr[i-1])
  }
  //console.log(setsuyakuKaisuu);

  const totalHeight=heights.reduce(function(total, data){return total + data});
  const setsuyakuSum=setsuyakuKaisuu.reduce(function(p, c) {return p + c;}); 
  console.log(totalHeight-setsuyakuSum);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 11676
from collections import defaultdict
from math import gcd


MOD = 1000000007
N = int(input())
both_zeros_cnt = 0
bads = defaultdict(lambda: [0, 0])
for _ in range(N):
    A, B = map(int, input().split())
    if A == 0 and B == 0:
        both_zeros_cnt += 1
        continue
    if B < 0 or (B == 0 and A < 0):
        A, B = -A, -B
    g = gcd(A, B)
    A, B = A // g, B // g
    if A > 0:
        bads[(A, B)][0] += 1
    else:
        bads[(B, -A)][1] += 1

ans = 1
for k, l in bads.values():
    ans *= (pow(2, k, MOD) - 1) + (pow(2, l, MOD) - 1) + 1
    ans %= MOD
print((ans + both_zeros_cnt - 1) % MOD)


Measured memory_bytes: 60592
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &e: v) cin >> e;

    vector<int> csum(n+1);
    for (int i = 0; i < n; ++i) csum[i+1] = csum[i] + v[i];

    int ans = 0;
    for (int len = max(n-k, 0); len < n; ++len) {
        for (int l = 0; l + len <= n; ++l) {
            priority_queue<int, vector<int>, greater<>> que;
            for (int i = 0; i < n; ++i) {
                if (l <= i && i < l + len) continue;
                que.push(v[i]);
            }
            int tmp = csum[l + len] - csum[l];
            int d = k - (n-len);
            while (d > 0 && !que.empty() && que.top() < 0) {
                tmp += que.top();
                que.pop();
                --d;
            }
            ans = max(ans, csum[n] - tmp);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int>ans(n);
  int x=0;
  for(int i=0;i<n;i++)
  {
    int temp;
    cin>>temp;
    ans[i]=temp;
    x=x^temp;
  }
  for(int i=0;i<n;i++)
  {
    int s=x^ans[i];
    cout<<s<<" ";
  }
  

  }


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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define endl "\n"

int32_t main()
{
	IOS;
	int n, m, x;
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= m; i++)
	{
		cin >> x;
		sum += x;
	}
	if (sum > n)
		cout << "-1" << endl;
	else
		cout << n - sum << endl;



	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// 2*3*5*7*11*13*17*19*23*29*31*37*41
// = 304,250,263,527,210

const int P = 13;
ll p[P]={2,3,5,7,11,13,17,19,23,29,31,37,41};

double calc(ll n){
    ll div = n;
    ll s = 1;
    rep(i,P){

        ll mul = 1;
        ll now = 1;
        while(n%p[i]==0){
            n /= p[i];
            now *= p[i];
            mul += now;
        }
        s *= mul;
    }

    return (double)s/div;
}

const ll LIM = 1000000000000010LL;
map<ll,double> memo;

void dfs(ll v, int idx, int nowct, int prect){
    if(v > LIM) return;
    if(idx == P) return;

    if(!memo.count(v)) memo[v] = calc(v);

    if(prect > nowct) dfs(v*p[idx], idx, nowct+1, prect);
    dfs(v, idx+1, 0, nowct);
}

int main(){
    dfs(1,0,0,50);

    double val = 0;
    vector<ll> v;
    vector<double> a;
    for(const auto &pp:memo){
        if(pp.se > val){
            val = pp.se;
            v.pb(pp.fi);
            a.pb(pp.se);
        }
    }
    v.pb(LIM);

    ll k;
    while(cin >>k,k){
        int idx = upper_bound(all(v), k) - v.begin();
        printf("%.10f\n", a[idx-1]);
    }
    return 0;
}



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

int main(){
	int n;
	cin >> n;
	
	struct job{ int a,b; };

	vector<job> jobs(n);
	rep(i,n){
		int a,b;
		cin >> a >> b;
			jobs[i] = job{a, b};
	}
	
	sort(jobs.begin(), jobs.end(), [](const job &a, const job &b) {
		return a.b < b.b;
	});
	
	int now = 0;
	bool isOK = true;
	for(auto j : jobs){
		now += j.a;
		if(now > j.b){
			isOK = false;
			break;
		}
		
	}
	
	if(isOK) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j+1] = A[j]
    j -= 1
  A[j+1] = v
  print(" ".join(map(str, A)))


Measured memory_bytes: 5596
#include<stdio.h>

int N;
int parent[100001];
int sibling[100001];
int degree[100001];

int calcDepth(int i) {
  if(parent[i] == -1) return 0;
  return calcDepth(parent[i]) + 1;
}
 
int calcHeight(int i) {
  int j, x, y;

  x = 0;

  for(j = 0; j < N; j++) {
    if(parent[j] == i) {
      y = calcHeight(j) + 1;
      if(y > x) x = y;
    }
  }

  return x;
}

int main() {
  int i, j, depth;
  int id, left, right;

  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  for(i = 0; i < N; i++) {
    scanf("%d %d %d", &id, &left, &right);

    if(left != -1) {
      parent[left] = id;
      sibling[left] = right;
      degree[id]++;
    }

    if(right != -1) {
      parent[right] = id;
      sibling[right] = left;
      degree[id]++;
    }
  }
  
  for(i = 0; i < N; i++) {
    depth = calcDepth(i);

    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, parent[i], sibling[i], degree[i], depth, calcHeight(i));

    if(depth == 0) {
      printf("root\n");
    }

    else if(degree[i] == 0) {
      printf("leaf\n");
    }

    else {
      printf("internal node\n");
    }
  }

  return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int N;

void recurse(string current, int maxi) {
    if (current.length() == N) {
        cout << current << endl;
        return;
    }

    for (int c = 0; c <= min(25, maxi + 1); c++)
        recurse(current + (char) (c + 'a'), max(maxi, c));
}

int main() {
    cin >> N;
    recurse("a", 0);
}


Measured memory_bytes: 1536
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class ASheepAndWolves {
public:
	void solve(std::istream& in, std::ostream& out) {
        int s,n;
        in >> s >> n;
        if(s<=n){
            out << "unsafe" << endl;
        }else{
            out << "safe" << endl;
        }
	}
};


int main() {
	ASheepAndWolves solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3588
def collatz(n):
    i=0
    while n != 1:
        if n%2==0:
            n = n/2
            i=i+1
        else:
            n=3*n+1
            i=i+1
    return(i)
    
while True:
    n=int(input())
    if n==0:
        break
    print(collatz(n))
    


Measured memory_bytes: 5604
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl

const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;






int main(){
    fastio();
    int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    set <int> s;
    s.insert(arr[0]);
    ll ans=1;
    for(int i=1;i<n;i++){
        auto it1=s.begin();
        int a=*it1;
        if(arr[i]<a){
            ans++;
        }
        s.insert(arr[i]);
    }
    cout<<ans<<endl;

    return 0;
}

 

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

int main() {
  int N,K ;
  cin>> N>>K;
  vector<char>data(N) ;
  for(int i=0 ;i<N ; i++){
    cin >> data.at(i);
  }
  if(data.at(K-1)=='A'){
    data.at(K-1)='a';}
    else if(data.at(K-1)=='B'){
    data.at(K-1)='b';}
   else if(data.at(K-1)=='C'){
    data.at(K-1)='c';}
   else if(data.at(K-1)=='D'){
    data.at(K-1)='d';}
   else if(data.at(K-1)=='E'){
    data.at(K-1)='e';}
   else if(data.at(K-1)=='F'){
    data.at(K-1)='f';}
   else if(data.at(K-1)=='G'){
    data.at(K-1)='g';}
   else if(data.at(K-1)=='H'){
    data.at(K-1)='h';}
   else if(data.at(K-1)=='I'){
    data.at(K-1)='i';}
   else if(data.at(K-1)=='J'){
    data.at(K-1)='j';}
   else if(data.at(K-1)=='K'){
    data.at(K-1)='k';}
   else if(data.at(K-1)=='L'){
    data.at(K-1)='l';}
   else if(data.at(K-1)=='M'){
    data.at(K-1)='m';}
   else if(data.at(K-1)=='N'){
    data.at(K-1)='n';}
   else if(data.at(K-1)=='O'){
    data.at(K-1)='o';}
   else if(data.at(K-1)=='P'){
    data.at(K-1)='p';}
   else if(data.at(K-1)=='Q'){
    data.at(K-1)='q';}
   else if(data.at(K-1)=='R'){
    data.at(K-1)='r';}
   else if(data.at(K-1)=='S'){
    data.at(K-1)='s';}
   else if(data.at(K-1)=='T'){
    data.at(K-1)='t';}
   else if(data.at(K-1)=='U'){
    data.at(K-1)='u';}
   else if(data.at(K-1)=='V'){
    data.at(K-1)='v';}
   else if(data.at(K-1)=='W'){
    data.at(K-1)='w';}
   else if(data.at(K-1)=='X'){
    data.at(K-1)='x';}
   else if(data.at(K-1)=='Y'){
    data.at(K-1)='y';}
   else if(data.at(K-1)=='Z'){
    data.at(K-1)='z';}
  for(int i=0 ;i<N ; i++){
    cout << data.at(i);
  }
  }

Measured memory_bytes: 256
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define deb(x) cout << #x << " = " << x << ' ';
#define rep(i, a, b) for(int i=(int)(a); i<(int)(b); i++)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 998244353;
const int N = 2e5+2;

int dp[3002][3002];

int main()
{
   string s, ts;
   cin >> s >> ts;

   int n = (int)s.size(), m = (int)ts.size();

   dp[0][0] = 0;

   rep(i, 1, n+1) {
      rep(j, 1, m+1) {
         if(s[i-1] == ts[j-1]) {
            dp[i][j] = 1 + dp[i-1][j-1];
         } else {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
         }
      }
   }

   string ans = "";

   int i = n, j = m;
   while(i > 0 and j > 0) {
      if(dp[i][j] > dp[i-1][j] and dp[i][j] > dp[i][j-1]) {
         ans += s[i-1];
         j --; i --;
      } else if(dp[i][j] == dp[i-1][j]) {
         i --;
      } else {
         j --;
      }
   }
  
   reverse(ans.begin(), ans.end());
   cout << ans;
   return 0;
}

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

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
int main(){
    int n;
    int v[100007];
    cin >> n;
    rep(i,n) cin >> v[i];
    
    map<int,int> cnt[2];
    rep(i,n) cnt[i%2][v[i]]++;

    vector<pair<int, int>> pairs[2];
    for(int i = 0; i < 2; i++){
        cnt[i][0] = 0;
        for(auto&& p : cnt[i]) pairs[i].push_back({p.second, p.first});
        sort(pairs[i].rbegin(), pairs[i].rend());
    }

    int ans;
    if (pairs[0][0].second != pairs[1][0].second){
        ans = n - pairs[0][0].first - pairs[1][0].first;
    }else {
        ans = n - max(pairs[0][1].first + pairs[1][0].first, pairs[0][0].first + pairs[1][1].first);
    }

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

Measured memory_bytes: 6520
import math

n, d = map(int, input().split())

points = []
for _ in range(n):
    x_list = list(map(int, input().split()))
    points.append(x_list)

def distance(x, y):
    dist = 0
    for i in range(d):
        dist += (x[i] - y[i]) ** 2

    return round(math.sqrt(dist), 2)

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = distance(points[i], points[j])
        if dist == dist//1:
            count += 1

print(count)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=2e5+5;
int sum[N],col[N],n;
ll ans[N],son[N];
vi v[N];
void DFS(int now,int fa)
{
	son[now]=1;
	for(int i=0;i<v[now].size();i++)
	{
		int to=v[now][i];
		if(to==fa)continue;
		DFS(to,now);
		son[now]+=son[to];
	}
}
void dfs(int now,int fa)
{
	ans[col[now]]+=(ll)son[now]*(ll)(n-son[now]-(ll)sum[col[now]]+1);
	sum[col[now]]+=son[now];
	int rem=sum[col[now]];
	ll pre=0;
	for(int i=0;i<v[now].size();i++)
	{
		int to=v[now][i];
		if(to==fa)continue;
		sum[col[now]]=(n-son[to]);
		dfs(to,now);
		ans[col[now]]+=pre*son[to];
		pre+=son[to];
	}
	sum[col[now]]=rem;
	return;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>col[i];
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	DFS(0,-1);
	dfs(0,-1);
	for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
	return 0;
}

Measured memory_bytes: 37964
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
 
using namespace std;
 
#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;
typedef pair<ll, int> P;

#define MAX_N 500
#define MAX_H 10000000

int n;
int h[MAX_N];


int main(){

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }

  sort(h, h + n, greater<int>());

  ll ans = 0;

  for(int i = 0; i < min(4, n); i++){
    ans += h[i];
  }
  ans++;
  
  int tmp = 0;
  int hh = 1;
  for(int i = 4; i < n; i++){
    
    if(h[i] <= hh)
      break;

    ans += h[i] - hh;

    tmp++;
    if(tmp == 4){
      hh++;
      tmp = 0;
    }
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 1172
#if 0
#endif

#include <iostream>
#include <vector>
using namespace std;

int N, temp[16][16], m;
struct zahyo
{
    int x;
    int y;
};
struct root
{
    bool x;
    bool y;
};

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        // 準備
        zahyo GOAL;
        cin >> GOAL.x >> GOAL.y;
        root data[GOAL.x + 1][GOAL.y + 1];
        for (int x = 0; x < GOAL.x; x++)
        {
            for (int y = 0; y < GOAL.y; y++)
            {
                data[x][y] = {.x = true, .y = true};
            }
        }
        for (int y = 0; y <= GOAL.y; y++)
        {
            data[GOAL.x][y] = {.x = false, .y = true};
        }
        for (int x = 0; x <= GOAL.x; x++)
        {
            data[x][GOAL.y] = {.x = true, .y = false};
        }
        cin >> m;
        for (int j = 0; j < m; j++)
        {
            zahyo temp1, temp2;
            cin >> temp1.x >> temp1.y >> temp2.x >> temp2.y;
            if (temp1.x <= temp2.x && temp1.y <= temp2.y)
            {
                if (temp1.x != temp2.x)
                {
                    data[temp1.x][temp1.y].x = false;
                }
                else
                {
                    data[temp1.x][temp1.y].y = false;
                }
            }
            else
            {
                if (temp1.x != temp2.x)
                {
                    data[temp2.x][temp2.y].x = false;
                }
                else
                {
                    data[temp2.x][temp2.y].y = false;
                }
            }
        }
        // 回答
        // 右に行ける場合 .x = true;
        // 下に行ける場合 .y = true;
        int nums[GOAL.x + 1][GOAL.y + 1];
        nums[0][0] = 1;
        for (int x = 1; x <= GOAL.x; x++)
        {
            nums[x][0] = data[x - 1][0].x ? nums[x - 1][0] : 0;
        }
        for (int y = 1; y <= GOAL.y; y++)
        {
            nums[0][y] = data[0][y - 1].y ? nums[0][y - 1] : 0;
        }
        for (int x = 1; x <= GOAL.x; x++)
        {
            for (int y = 1; y <= GOAL.y; y++)
            {
                int x_r, y_r;
                x_r = data[x - 1][y].x ? nums[x - 1][y] : 0;
                y_r = data[x][y - 1].y ? nums[x][y - 1] : 0;
                nums[x][y] = x_r + y_r;
            }
        }
        if (nums[GOAL.x][GOAL.y] > 0)
        {
            cout << nums[GOAL.x][GOAL.y] << endl;
        }
        else
        {
            cout << "Miserable Hokusai!" << endl;
        }
    }
}



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

using namespace std;


int main() {
  
    char a,b;
    cin>>a>>b;
  if(a<b)
      printf("<");
  
  else if(a>b)
        printf(">");
  
  else
     printf("=");
    	return 0;
} 

Measured memory_bytes: 256
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]
import sys
sys.setrecursionlimit(100000000)

adj = [[] for _ in range(N)]
for a,b in ab:
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)
    

def dfs(x,s,flags):
    vlist = adj[x]
    flags = list(flags)
    flags[x] = False
    flags = tuple(flags)
    if sum(flags) == 0:
        return 1
    s = 0
    for v in vlist:    
        if flags[v]:
            s += dfs(v,s,flags)
    return s        

Flag = [True] * N
Flag[0] = False
ans = dfs(0,0,tuple(Flag))
print(ans)



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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;



void solve(){
	string s;
	cin>>s;
	if(s.length()<3 || s[0]!='A') cout<<"WA";
	else {
		bool ok = false;
		for(int i=0;i<s.length();i++)
			if(s[i]=='C'){
				if(i>=min(2LL,(ll)s.length()-1LL)&&i<=max(2LL,(ll)s.length()-2LL))
				{ok = true;break;}
				else
				{ok = false;break;}
			}
		if(!ok) cout<<"WA";
		else{
			ll ans =0;
			for(int i=1;i<s.length();i++)
				ans+=(s[i]>=65 && s[i]<=90);
			puts(ans==1?"AC":"WA");
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main()
{
    int N, M;
    cin >> N >> M ;
    vector<int> cnt(M);
    REP(i,N){
        int K;
        cin >> K;
        REP(j,K){
            int A;
            cin >> A;
            A--;
            cnt[A]++;
        }
    }

    int ans=0;
    REP(i,M){
        if(cnt[i]==N){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	string s0 = "CODEFESTIVAL2016", s;
	cin >> s;
	int c = 0;
	for (int i = 0; i < s0.length(); i++)
		if (s[i] != s0[i])
			c++;
	cout << c;
	return 0;
}


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

// Definitions
// #define MAXN 210
#define MAXN 200010
#define MOD 998244353
#define elif else if
typedef long long int64;
#define File(s) freopen(#s ".in", "r", stdin), freopen(#s ".out", "w", stdout)

// Variables
int n, k, l[MAXN], r[MAXN];

// Pynamic Programming
int dp[MAXN], pfxsum[MAXN];
inline void DP() {
  dp[1] = 1;
  for (int cur = 1, begin, end; cur <= n; cur++) {
    for (int idx = 1; idx <= k; idx++) {
      begin = max(1, cur - r[idx]);
      end = max(0, cur - l[idx]);
      // for (int last = begin; last <= end; last++) {
      //   dp[cur] = (dp[cur] + dp[last]) % MOD;
      // }
      if (begin <= end) {
        dp[cur] = dp[cur] + (pfxsum[end] + MOD - pfxsum[begin - 1]) % MOD;
        dp[cur] %= MOD;
      }
    }
    pfxsum[cur] = (pfxsum[cur - 1] + dp[cur]) % MOD;
  }
}

// Functions
inline void Monitor() {
  for (int i = 1; i <= n; i++) {
    printf("%d ", dp[i]);
  }
  puts("");
}
inline void Process() {
  DP();
}
inline void ReadIn() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", l + i, r + i);
  }
}
inline void PrintAns() {
  // Monitor();
  printf("%d\n", dp[n]);
}

int main() {
#ifndef ONLINE_JUDGE
  File(data);
#endif
  ReadIn();
  Process();
  PrintAns();
  return 0;
}
/*

==== O(n^2) {Diffuse} ====
> dp[1] = 1;
> for (int cur = 1; cur <= n; cur++) {
>   for (int idx = 1; idx <= k; idx++) {
>     for (int add = l[idx]; add <= r[idx]; add++) {
>       dp[cur + add] = (dp[cur + add] + dp[cur]) % MOD;
>     }
>   }
> }
==== O(n^2) {Collect} ===
> dp[1] = 1;
> for (int cur = 1, begin, end; cur <= n; cur++) {
>   for (int idx = 1; idx <= k; idx++) {
>     begin = max(1, cur - r[idx]);
>     end = max(0, cur - l[idx]);
>     for (int last = begin; last <= end; last++) {
>       dp[cur] = (dp[cur] + dp[last]) % MOD;
>     }
>   }
> }

*/

Measured memory_bytes: 3264
from operator import itemgetter as get
N = int(input())

A = map(int, input().split())
SA = SB = 0
ABI = sorted(((b:=max(N-i, i-1)*a, SA:=SA+a, SB:=SB+b) and (a, b, i) for i, a in enumerate(A, 1)), reverse=True)

def solve(a, i, prev, th, tha):
  pl, pr, ps = 0, -1, 0
  for l, r, s in prev:
    if s < th-max(l,r)*tha:
      continue
    if pr == r-1:
      yield l, r-1, max(s+abs(r-i)*a, ps+abs(i-pl)*a)
    else:
      if pl:
        yield pl+1, pr, ps+abs(i-pl)*a
      yield l, r-1, s+abs(r-i)*a
    pl, pr, ps = l, r, s
  yield pl+1, pr, ps+abs(i-pl)*a

prev = [(1, N, 0)]
pm = 0
for j, (a,b,i) in enumerate(ABI):
  M = 0
  prev = [(M:=max(M,s),) and (l, r, s) for l, r, s in solve(a,i, prev, pm-SB, SA)]
  pm = M
  SA -= a
  SB -= b

print(pm)


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

#define ll long long
#define N 200010
const ll p = 1e9 + 7;
int n, m, k;
ll fac[N], inv[N];
ll qmod(ll base, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1) {
			res = res * base % p;
		}
		base = base * base % p;
		n >>= 1;
	}
	return res;
}
ll C(int n, int m) {
	return fac[n] * inv[m] % p * inv[n - m] % p;
}
ll f(int n) {
	return (1ll * n * (n + 1) / 2) % p;
}


int main() {
	fac[0] = 1;
	for (int i = 1; i < N; ++i) {
		fac[i] = (fac[i - 1] * i % p);
	}
	inv[200000] = qmod(fac[200000], p - 2);
	for (int i = 200000; i >= 1; --i) {
		inv[i - 1] = (inv[i] * i % p);
	}
	while (scanf("%d%d%d", &n, &m, &k) != EOF) {
		ll res = 0;
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				ll tot = ((f(j - 1) + f(m - j)) * n % p + (f(i - 1) + f(n - i)) * m % p) % p; 
				(res += tot * C(n * m - 2, k - 2) % p) %= p;
			}
		}
		printf("%lld\n", res * qmod(2, p - 2) % p); 
	}
	return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;




int main() {

	int a, b;
	cin >> a >> b;

	if (a <= 5) {
		cout << 0 << endl;
	}
	else if (a > 12) {
		cout << b << endl;
	}
	else {
		cout << b / 2 << endl;
	}
	
}

Measured memory_bytes: 256
open Batteries
open BatPrintf

let scan fmt f =
  BatScanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> BatString.split_on_char ' '
  |> List.map cnv

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let n = scan "%d" identity
let a = scan_list Int.of_string

let () =
  BatList.filter (fun x -> x mod 2 = 0) a
  |> BatList.for_all (fun x -> x mod 3 = 0 || x mod 5 = 0)
  |> (fun b -> if b then "APPROVED" else "DENIED")
  |> printf "%s\n"


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

using namespace std;

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

Measured memory_bytes: 3636
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var (
		a, b int
		s    string
	)

	fmt.Scan(&a, &b)

	if a%2 != b%2 {
		s = "IMPOSSIBLE"
	} else {
		s = strconv.Itoa((a + b) / 2)
	}

	fmt.Println(s)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){

	int N,K;
	cin>>N>>K;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	long long ok = Inf,ng = 0;
	
	while(ok-ng>1){
		long long t = K;
		long long mid = (ok+ng)/2;
		
		for(int i=0;i<N;i++){
			t -= (A[i] + mid-1)/mid-1;
		}
		if(t>=0){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	
	cout<<ok<<endl;
	
	
	return 0;
}

Measured memory_bytes: 4760
#include<iostream>
#include<algorithm>
using namespace std;
struct stu{
	int numberr,rankk;
	bool operator < (const stu s)
	{
		return rankk<s.rankk;
	}
};
stu ss[100010];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ss[i].numberr=i;
		cin>>ss[i].rankk;
	}
	sort(ss+1,ss+n+1);
	for(int i=1;i<=n;i++)
	{
		cout<<ss[i].numberr;
		if(i!=n)
			cout<<" ";
	}
	cout<<endl;
 } 

Measured memory_bytes: 1536
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	listH := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&listH[i])
	}

	result := 1
	max := listH[0]
	for i := 0; i < n-1; i++ {
		if max <= listH[i+1] {
			max = listH[i+1]
			result++
		}

	}

	fmt.Println(result)

}


Measured memory_bytes: 512
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h,w = li()
n = ni()
a = list(li())

grid = [[0 for _ in range(w)] for _ in range(h)]

k = 0
cur = k+1
cnt = a[k]
for hi in range(h):
    for wj in range(w):
        grid[hi][wj] = cur
        cnt -= 1
        
        if cnt == 0:
            k += 1
            if k == n:
                break

            cur = k+1
            cnt = a[k]
            
for hi,row in enumerate(grid):
    if hi%2 == 0:
        print(*row)
    else:
        row = row[::-1]
        print(*row)
        

Measured memory_bytes: 3920
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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()
{
cin.tie(0);
ios::sync_with_stdio(false);

int n;
string s;
cin >> n >> s;

int ans = 1;
rep(i,n-1) if(s[i] != s[i+1]) ans++;

cout << ans << endl;

return 0;
}

Measured memory_bytes: 512
# 2019-11-15 14:12:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *a = [int(x) for x in sys.stdin.read().split()]
    a = [None] + a

    in_or_not = [0 for _ in range(n+1)]
    for i in range(n, 0, -1):
        count = 0
        for j in range(2 * i, n+1, i):
            count += in_or_not[j]
        
        in_or_not[i] = a[i] ^ count % 2
    

    print(in_or_not.count(1))
    for i in range(1, n+1):
        if in_or_not[i] == 1:
            print(i, end=' ')




if __name__ == "__main__":
    main()


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

struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};

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

    int n, m;
    cin >> n >> m;
    
    UnionFind uf(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
    }

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int s, t;
        cin >> s >> t;
        if(uf.same(s, t)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3200
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

const long long INF = 1LL << 60;

int main() {
	long long N, K;
	cin >> N >> K;
	vector<long long> h(N + 1);
	h.at(0) = 0;
	for (int i = 1; i <= N; i++) {
		cin >> h.at(i);
	}

	vector<long long> dp(110000);
	for (int i = 0; i < dp.size(); i++) {
		dp.at(i) = INF;
	}

	dp.at(0) = 0;
	dp.at(1) = 0;
	dp.at(2) = abs(h.at(2) - h.at(1));

	for (int i = 2; i <= N; i++) {
		for (int j = 1; j <= K; j++) {
			if (j >= i) break;
			dp.at(i) = min(dp.at(i), dp.at(i - j) + abs(h.at(i) - h.at(i - j)));
		}
	}

	cout << dp.at(N) << endl;
}

Measured memory_bytes: 4820
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
ans=10**9
for i in range(4**N):
  tmp=[0]*N
  s=[0,0,0]
  for j in range(N):
    k = (i // (4**j))%4
    tmp[j]=k
    if k>0:
      s[k-1]+=1
  if s[0]==0 or s[1]==0 or s[2]==0:
    continue
  else:
    ans_tmp=0
    ans_tmp=10*(max(s[0]-1,0)+max(s[1]-1,0) +max(s[2]-1,0))
    s[0],s[1],s[2]=0,0,0
    for j in range(N):
      if tmp[j]==0:
        continue
      s[tmp[j]-1]+=l[j]
    ans_tmp+=abs(s[0]-A)+abs(s[1]-B)+abs(s[2]-C)
    ans=min(ans,ans_tmp)
print(ans)
    
    

Measured memory_bytes: 3188