akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;

#define EPS (1e-7)
#define INF (1e16)
#define PI (acos(-1))
struct max_flow {
    struct edge { int to;
    ll cap;
    int rev; };
    ll V;
    vector<vector<edge>> G;
    vector<int> itr, level;

    max_flow(int V) : V(V) { G.assign(V,vector<edge>()); }

    void add_edge(int from, int to, ll cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
    }

    void bfs(int s) {
        level.assign(V,-1);
        queue<int> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for(auto &e: G[v]){
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    ll dfs(int v, int t, ll f) {
        if (v == t) return f;
        for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    ll run(int s, int t) {
        ll ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s, t, INF)) > 0) ret += f;
        }
        return ret;
    }
};


int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    ll a[105];
    ll sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        ll now = a[i];
        if(now < 0){
            now = 0;
        }
        sum += now;
    }
    max_flow graph(115);
    for(int i = 1; i <= n; i++){
        if(a[i] >= 0){
            graph.add_edge(i, 110, a[i]);
        } else {
            graph.add_edge(0, i, -a[i]);
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j < i; j++){
            if((i % j) != 0){
                continue;
            }
            graph.add_edge(j, i, INF);
        }
    }
    cout << sum - graph.run(0, 110) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<long long,bool> Pair;

int main(){

double R,PI = 3.14159265358979323846;


cin >> R;

cout << 2.0*R*PI << endl;

return 0;

}

Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    vector<string> ans;
    ans.push_back(s);
    ans.push_back(t);
    sort(ans.begin(), ans.end());
    if ((ans[0] == s) && (s != t))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())

"""========main code==============="""
t=ii()

a=ll()
s=1
f=0
val=10**18
if 0 in a:
    print(0)
else:    
    for i in a:
        s*=i
        if(s>val):
            f=1
            break
    if f:
        print(-1)
    else:
        print(s)


Measured memory_bytes: 84164
function main(input){
  let [a, b, c, k] = input.split(' ').map(Number);
  if(a >= k){
    console.log(k);
  }else if((a+b) >= k){
    console.log(a);
  } else {
    console.log(a - (k - (a+b)));
  }
}

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

Measured memory_bytes: 29860
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    auto dq = new Deque!int(a.length);
    foreach (e; a) {
        int p = dq.lowerBound(e);
        if (p == 0) dq.pushFront(e);
        else dq[p - 1] = e;
    }
    return dq.size();
}

void main() {
    int n = readint;
    int[] a;
    foreach (_; 0..n) a ~= readint;
    writeln(calc(a));
}

class Deque(T) {
    private T[] _buffer;
    private size_t _size;
    private int _front;
    private int _back;

    this(size_t size) {
        _buffer = new T[size * 3];
        _size = 0;
        _front = _back = cast(int)size * 3 / 2;
    }

    @property bool empty() const {
        return _size == 0;
    }

    int size() const {
        return cast(int)_size;
    }

    void pushFront(T elt) {
        _buffer[empty ? _front : --_front] = elt;
        _size++;
    }

    void pushBack(T elt) {
        _buffer[empty ? _back : ++_back] = elt;
        _size++;
    }

    T opIndex(size_t index) const {
        return _buffer[_front + index];
    }

    T opIndexAssign(T value, size_t index) {
        return _buffer[_front + index] = value;
    }

    int lowerBound(T value) const {
        int lo = 0;
        int hi = cast(int)size() - 1;
        int minIndex = cast(int)size();
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (this[m] >= value) {
                minIndex = min(minIndex, m);
                hi = m - 1;
            }
            else lo = m + 1;
        }
        return minIndex;
    }
}


Measured memory_bytes: 4860
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int n = reader.nextInt();
        int s = 0;
        int buf = n;
        while (buf > 0) {
            s += buf % 10;
            buf /= 10;
        }
        System.out.println(n % s == 0 ? "Yes" : "No");
        reader.close();
    }
}

Measured memory_bytes: 23764
require 'complex'

n, d = gets.chomp.split(" ").map(&:to_i)
pts = []
c = 0
if n > 0 then
  n.times.map { pts.push(gets.chomp.split(" ").map(&:to_i).to_ary) }
  pts.each_with_index do |px, i|
    break if (pts.length - 1) == i 
    ((i + 1)..(pts.length - 1)).each do |j|
      py = pts[j]
      sum = 0
      (0..(d - 1)).each do |k|
        sum += (px[k] - py[k]).abs**2
      end
      x = Math.sqrt(sum)
      c += 1 if x.to_s =~ /\A[1-9][0-9]*\.0\z/
    end
  end
end
puts "#{c}"



Measured memory_bytes: 1788
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	if a+b == 15 {
		fmt.Println("+")
	} else if a*b == 15 {
		fmt.Println("*")
	} else {
		fmt.Println("x")
	}
}


Measured memory_bytes: 640
//In the name of God

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

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

#define int ll

const int N = 3e3+10 , mod = 1e9+7;

int dp[N][N] , a[N] , n;
bool mk[N][N];

int go(int l , int r){
   if(mk[l][r])
      return dp[l][r];
   mk[l][r] = true;
   int x = 1;
   if((r - l + 1) % 2 != n % 2)
      x = -1;
   if(l == r)
      return dp[l][r] = x * a[l];
   if(x == 1)
      return dp[l][r] = max(a[l] + go(l + 1 , r) , a[r] + go(l , r - 1));
   else
      return dp[l][r] = min(-a[l] + go(l + 1 , r) , -a[r] + go(l , r - 1));
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(9);
   cin >> n;
   for(int i = 0 ; i < n ; i++)
      cin >> a[i];
   cout << go(0 , n - 1);
   return 0;
}


Measured memory_bytes: 78464
N,K = map(int,input().split())
H = list(map(int, input().split()))

DP = [0 for _ in range(N)]

for i in range(1,N):
	temp = []
	for j in range(min(i,K)):
		temp.append(DP[i-(j+1)] + abs(H[i]-H[i-(j+1)]))

	DP[i] = min(temp)

print(DP[N-1])

Measured memory_bytes: 56800
import sys
input = sys.stdin.readline
import heapq
N, M = map(int, input().split())
day = [[] for _ in range(100001)]
for i in range(N):
    a, b = map(int, input().split())
    day[a].append(b)


queue = []
heapq.heapify(queue)
ans = 0
for i in range(1, M+1):
    for j in day[i]:
        heapq.heappush(queue, -j)
    if len(queue) > 0:
        ans -= heapq.heappop(queue)

print(ans)


Measured memory_bytes: 68144
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=998244353;
const long long inf=1ll<<61;

signed main(){
	int n,d;cin>>n>>d;
	int ans=0;
	rep(i,n){
		int x,y;cin>>x>>y;
		x*=x;y*=y;
		if(x+y<=d*d)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int k;
	cin>>k;
	cout<<(k/2)*(k-k/2)<<endl;
	return 0;
}

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

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

ll n, x;

ll solve(ll a, ll b)
{
    if(a<b) return solve(b, a);
    if(a%b==0) return b*(a/b)*2-b;
    return solve(a%b, b)+a/b*b*2;
}

int main()
{
    int i, j;
    scanf("%lld%lld", &n, &x);
    printf("%lld", solve(x, n-x)+n);
}


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

using namespace std;
const double PI = (acos(-1));
const long long MOD = pow(10, 9) + 7;

int main()
{
    string s = "ACL";
    int N;
    cin >> N;
    
    for(int i=0; i<N; i++)
    {
        cout << s;
    }
}

Measured memory_bytes: 3620
N,Q = gets.split.map &:to_i
S = gets.chomp
ss = []
(1...S.size).each{ |i|
  if S[i-1..i] == "AC"
    ss << [i,i+1]
  end
}
#p sb,se
Q.times {
  l,r = gets.split.map &:to_i
  il = (0...ss.size).bsearch{ |i| l <= ss[i][0] } || ss.size
  ir = (0...ss.size).bsearch{ |i| r < ss[i][1] } || ss.size
  #p [l,r,il,ir,S[l-1..r-1]]
  p [ir - il, 0].max
}


Measured memory_bytes: 8956
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define f first
#define s second
#define mk make_pair
#define MOD 1000000007
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	ll v,h;
	cin>>v>>h;
	if(v==1 || h==1)
	cout<<"1";
	else if((v*h)%2==0)
	cout<<(v*h)/2;
	else
	cout<<((v*h)+1)/2;
  return 0;
}


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

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    int a_tmp;
    while(cin >> a_tmp){
        a.push_back(a_tmp);
    }
    sort(a.begin(), a.end(), greater<int>());

    int score = 0;
    for(int i=0;i<N;i++){
        if( i%2 == 0){
            score += a[i];
        }else{
            score -= a[i];
        }
    }
    cout << score << endl;


    return 0;
}

Measured memory_bytes: 256
using System;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var w = int.Parse(input[0]);
            var h = int.Parse(input[1]);
            var x = int.Parse(input[2]);
            var y = int.Parse(input[3]);
            var r = int.Parse(input[4]);

            if (x + r <= w && x - r >= 0 &&
                y + r <= h && y - r >= 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}



Measured memory_bytes: 17948
#include <stdio.h>
#include "iostream"
#include "deque"
#include "vector"
#include "string"

using namespace std;

int main(){
    int H, W;
    const int INF = 1e9+1;

    cin >> H >> W;

    vector<string> S(H);

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

    int cost_max = 0;
    for(int s_y = 0; s_y < H; s_y++){
        for(int s_x = 0; s_x < W; s_x++){
            for(int g_y = 0; g_y < H; g_y++){
                for(int g_x = 0; g_x < W; g_x++){
                    if(s_y != g_y || s_x != g_x){
                        if(S[s_y][s_x] == '.' && S[g_y][g_x] == '.'){
                            vector<vector<int>> dist(H, vector<int>(W, INF));
                            deque<int> que_y;
                            deque<int> que_x;
                            que_y.push_front(s_y);
                            que_x.push_front(s_x);
                            dist[s_y][s_x] = 0;

                            while(!que_y.empty()){
                                int y = que_y.front();
                                int x = que_x.front();
                                que_y.pop_front();
                                que_x.pop_front();

                                for(int i = -1; i <= 1; ++i){
                                    for(int j = -1; j <= 1; ++j){
                                        if(abs(i) + abs(j) == 1){
                                            int n_x = x + i;
                                            int n_y = y + j;
                                            if(n_x >= 0 && n_y >= 0 && n_x < W && n_y < H){
                                                if(S[n_y][n_x] == '.' && dist[n_y][n_x] > dist[y][x] + 1){
                                                    dist[n_y][n_x] = dist[y][x] + 1;
                                                    que_y.push_back(n_y);
                                                    que_x.push_back(n_x);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            cost_max = max(cost_max, dist[g_y][g_x]);
                        }
                    }
                }
            }
        }
    }
    cout << cost_max << endl;

    return 0;
}

Measured memory_bytes: 3180
n=int(input())
d={}
l=[]
for i in range(n):
  s=input()
  if s not in d:
    d[s]=1
  else:
    d[s]=d[s]+1
k=max(d.values())
for i,j in d.items():
  if j==k:
    l.append(i)
l.sort()
for i in range(len(l)):
  print(l[i])

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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

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

	string s;
	cin >> s;
	for (auto &i : s)
		if (i == '?')
			i = 'D';
	cout << s << "\n";

	return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int a, b, k;
    cin >> a >> b >> k;
    
    for (int i = min(a, b); i >= 1; --i) {
        if (a % i == 0 && b % i == 0)--k;
        if (k == 0) {
            cout << i << endl;
            return;
        }
    }
}

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


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

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

  int n;
  cin >> n;

  vector<int> divisor_cnt(n + 1);
  for (int i = 1; i <= n; i++) {
    divisor_cnt[i]++;
    for (int j = i + i; j <= n; j += i) {
      divisor_cnt[j]++;
    }
  }

  int answer = 0;
  for (int i = 1; i <= n; i++) {
    answer += i * divisor_cnt[i];
  }
  cout << answer << '\n';
}


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

typedef long long ll;

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

void solve() {
	int n,k;
	cin >> n >> k;

	int a[n];
	F0R(i,n) cin >> a[i];

	int front = 0, back;

	FOR(i,k,n) {
		if(a[i] > a[front++]) cout << "Yes\n";
		else cout << "No\n";
	}
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}



Measured memory_bytes: 4584
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

// Data :
type Data struct {
	X, N int
}

// Datas :
type Datas []Data

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	return p[i].X > p[j].X
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	x := make(map[int]int)
	for i := 0; i < N; i++ {
		a := getInt()
		x[a]++
	}
	for i := 0; i < M; i++ {
		b, c := getInt(), getInt()
		x[c] += b
	}

	y := make(Datas, 0)
	for i, v := range x {
		y = append(y, Data{i, v})
	}

	sort.Sort(y)

	ans := 0
	cnt := 0
	for _, v := range y {
		n := min(v.N, N-cnt)
		ans += n * v.X
		cnt += n
		if cnt == N {
			break
		}
	}
	// out(y)
	out(ans)

}


Measured memory_bytes: 23040
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    char S[5];

    scanf("%s", S);

    bool contExist = false;

    for (size_t i = 0; i < 3; i++) {
        if (S[i] == S[i + 1]) {
            contExist = true;
            break;
        }
    }

    puts(contExist ? "Bad" : "Good");

    return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())

    tmp = ((N-1)*(N-2)) // 2
    if K > tmp:
        print(-1)
        return
    ans = [(1, i) for i in range(2, N+1)]
    count = tmp - K
    if count > 0:
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                ans.append((i, j))
                count -= 1
                if count == 0:
                    break
            if count == 0:
                break
    
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i][0], ans[i][1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using ll = long long;
using lli = long long int;

lli h, w;
std::vector<std::string> vec;
std::vector<std::vector<lli>> visited;
std::string s;
std::vector<int> x_s;
std::vector<int> y_s;

int main() {
    lli ans = 0;
    x_s = {0, 0, 1, -1};
    y_s = {1, -1, 0, 0};
    std::cin >> h >> w;
    vec.assign(h, "a");
    for (int i = 0; i < h; i++) {
        std::cin >> s;
        vec[i] = s;
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (vec[i][j] == '.') {
                visited.assign(h, std::vector<lli>(w, 0));
                std::queue<std::vector<lli>> q;
                q.push({i, j, 0});
                while (!q.empty()) {
                    auto point = q.front();
                    lli x = point[1];
                    lli y = point[0];
                    if (visited[y][x] == 1) {
                        q.pop();
                        continue;
                    }
                    if (point[2] > ans) {
                        ans = point[2];
                    }
                    visited[y][x] = 1;
                    for (int k = 0; k < 4; k++) {
                        if (y+y_s[k] >= 0 && x+x_s[k] >= 0 && y+y_s[k] < h && x+x_s[k] < w && vec[y+y_s[k]][x+x_s[k]] != '#' && visited[y+y_s[k]][x+x_s[k]] != 1) {
                            q.push({y+y_s[k], x+x_s[k], point[2]+1});
                        }
                    }
                    q.pop();
                }
            }
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define NEWL EVAL({cout << '\n';})
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int even = 0;
    REP(i, n) {
        int j = i;
        while(j+1 < n and a[j+1] == a[i]) {
            j++;
        }
        int l = j-i+1;
        if (l % 2 == 0) {
            even++;
        }
        i = j;
    }
    int dis = unique(a.begin(), a.end()) - a.begin();
    cout << dis - (even & 1) << '\n';
}






























Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	int A[]= new int[1000001], i, q;

	Scanner s = new Scanner(System.in);
	int n = s.nextInt();

	for(i=0; i<n; i++){
	    A[i] = s.nextInt();
	}
  
	q = partition(A, 0, n-1);

	for(i=0; i<n; i++){
	    if(i!=0) System.out.print(" ");
	    if(i==q) System.out.print("[");
	    System.out.print(A[i]);
	    if(i==q) System.out.print("]");
	}
	System.out.println();
    }
    
    public static int partition(int A[], int p, int r){
	int x, i, j, t;
	x = A[r];
	i = p-1;
	for(j=p; j<r; j++){
	    if(A[j]<=x){
		i++;
		t = A[i]; A[i] = A[j]; A[j] = t;
	    }
	}
	t = A[i+1]; A[i+1] = A[r]; A[r] = t;
	return i+1;
    }
}

Measured memory_bytes: 79492
#include <iostream>
#include <string>    
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, h, w;

int main() {
	cin >> n;
	cin >> h;
	cin >> w;
	cout << (n-h+1)*(n-w+1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size() - 1 ; i++){
        if (s.at(i)==s.at(i+1)){
            cnt++;
        }
    }
    cout << s.size()-cnt << endl;
}


Measured memory_bytes: 512
//
// ABC086C
//
//

#include <iostream>
using namespace std;

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  // 初期状態
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  // 1-index にしておく

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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


int main() {
	int K,Q;
	cin >> K>> Q;
	vector<int>D(K);
	for (int n = 0;n<K;++n) {
		cin >> D[n];
	}
	vector<long long >N(Q); 
	vector<long long>X(Q); 
	vector<long long>M(Q);
	for (int n = 0;n<Q;++n) {
		cin >> N[n] >> X[n] >>M[n];
	}
	vector<long long>Ans(Q);
	for (int n = 0; n < Q; ++n) {
		vector<int>modD(K);
		for (int m = 0;m<K;++m) {
			modD[m] = D[m] % M[n];
		}
		long long num = X[n] % M[n];
		long long zero = 0;
		for (int m = 0; m < K; ++m) {
			long long count = (N[n]-1)/K;
			if (m < (N[n] - 1) % K) {
				count++;
			}
			num += count * modD[m % K];
			if (0 == modD[m % K]) {
				zero += count;
			}
		}
		long long kuriagari = (num)/M[n] -(X[n] % M[n])/M[n];
		Ans[n] = (N[n]-1) - zero - kuriagari;
	}
	for (int n = 0;n<Q;++n) {
		cout <<Ans[n]<<endl;
	}
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    bool odd = true;
    bool even = true;
    for(int i = 1; i < S.length(); i = i+2){
        if (S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D'){
            even = true;
        }else{
            even = false;
            break;
        }
    }
    for(int i = 0; i < S.length(); i = i+2){
        if (S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D'){
            odd = true;
        }else{
            odd = false;
            break;
        }
    }
 
    if (odd && even){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

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

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

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

vector<bool> visited(100010, false);
vector<vector<int>> G(100010);

ll n, k;
ll ans;

void dfs(int cv, int depth){
    visited[cv] = true;

    int chcnt = 0;
    for(auto nv : G[cv]){
        if(!visited[nv]){
            chcnt++;
            dfs(nv, depth+1);
        }
    }

    if(depth == 0){
        for(int i=0; i<chcnt; i++){
            (ans *= (k - (i + 1))) %= MOD;
        }
    }
    else{
        for(int i=0; i<chcnt; i++){
            (ans *= (k - (i + 2))) %= MOD;
        }
    }

    return ;
}

int main(){
    cin>>n>>k;
    for(int i=0; i<n-1; i++){
        int a, b; cin>>a>>b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    ans = k;

    dfs(0, 0);

    cout << ans % MOD << endl;
}

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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int p = 0;
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        p ^= x & 1;
    }
    if (p) puts("NO");
    else puts("YES");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>

using namespace std;

struct process {
  string name;
  int time;
  int time_remain;
};

int main()
{
  char tmp[100];
  cin >> tmp;
  int n = atoi(tmp);

  cin >> tmp;
  int q = atoi(tmp);

  string *name = new string[n];
  int *time = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> name[i];
    cin >> time[i];
  }

  process *queue = new process[n];
  int start = 0;
  int end = -1;
  for (int i = 0; i < n; i++) {
    queue[++end].name = name[i];
    queue[end].time = time[i];
    queue[end].time_remain = time[i]; 
  }

  int total_time = 0;
  int q_size = n;
  while (1) {
    if (queue[start].time_remain <= q) {
      total_time += queue[start].time_remain;
      cout << queue[start].name << " " << total_time << endl;
      start++;
      if (start >= n) {
        start = 0;
      }
      q_size--;
      if (q_size == 0) {
        break;
      }
    }
    else {
      total_time += q;
      end++;
      if (end >= n) {
        end = 0;
      }
      queue[end].name = queue[start].name;
      queue[end].time = queue[start].time;
      queue[end].time_remain = queue[start].time_remain - q;      

      start++;
      if (start >= n) {
        start = 0;
      }
    }
  }
}


Measured memory_bytes: 6740
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <assert.h>
using namespace std;
#define int long long
int MOD = 1000000007;


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int a;
	vector<int> A;
	vector<int> B;
	for (int i = 0; i < N; i++) {
		cin >> a;
		if (a >= 0)A.push_back(a);
		else B.push_back(-a);
	}

	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());
	vector<pair<int, int> > res(N - 1);

	for (int i = 0; i < N - 1; i++) {
		if ((int)A.size() == 0) {
			int k1 = B.back(); B.pop_back();
			int k2 = B.back(); B.pop_back();

			res[i].first = -k1;
			res[i].second = -k2;

			A.push_back(-k1 + k2);

		}
		else if (B.size() == 0) {
			int k1 = A.back(); A.pop_back();
			int k2 = A.back(); A.pop_back();

			if (A.size() == 0) {
				res[i].first = k2;
				res[i].second = k1;

				A.push_back(-k1 + k2);
			}
			else {
				res[i].first = k1;
				res[i].second = k2;

				B.push_back(-k1 + k2);
			}

		}
		else {
			int k1 = A.back(); A.pop_back();
			int k2 = B.back(); B.pop_back();

			if (A.size() == 0) {
				A.push_back(k1 + k2);

				res[i].first = k1;
				res[i].second = -k2;
			}
			else {
				B.push_back(k1 + k2);

				res[i].first = -k2;
				res[i].second = k1;
			}


		}

	}
	//assert((int)A.size() == 1);
	int t = A[0];

	cout << t << endl;
	for (int i = 0; i < N - 1; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}

}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;
int main() {
   int a, b, c;
   cin >> a >> b >> c;
   int s1, s2 ,s3;
   s1 =  min({a, b, c});
   s3 = max({a, b, c});
   s2 = a + b + c - s1 - s3;
   printf("%d %d %d\n", s1, s2, s3);
   return 0;
}


Measured memory_bytes: 3164
#include<stdio.h>

int main(void)
{
	int height, width;
	int i, j;

	while (1)
	{

		scanf("%d %d", &height, &width);
		/*たてよこ０ｃｍならプログラム終了*/
		if (height == 0 && width == 0)
		{
			break;
		}
		/*一行目出力*/
		for (j = 0; j < width; j++)
		{
			printf("#");
		}
		printf("\n");
		/*2行目から最後の行-1まで出力*/
		for (i = 0; i < height-2; i++)
		{
			printf("#");
			/*.の出力部分*/
			for (j = 0; j < width-2; j++)
			{
				printf(".");
			}
			printf("#");
			printf("\n");
		}
		/*最後の行出力*/
		for (j = 0; j < width; j++)
		{
			/*たてよこ1ｃｍなら＃は出力しない*/
			if (height == 1 && width == 1)
			{
				break;
			}
			printf("#");
		}
		printf("\n");
		printf("\n");   //空行
	}
	return 0;
}


Measured memory_bytes: 2052
using System;
using System.Linq;
using System.Collections.Generic;

namespace ARC087_D___FT_Robot
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver() ? "Yes" : "No");
        }
        static bool solver()
        {
            var s = Console.ReadLine();
            var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var x = xy[0];
            var y = xy[1];

            var moveX = new List<int>();
            var moveY = new List<int>();
            var isX = true;
            var moveCount = 0;
            foreach (char c in s)
            {
                if (c == 'T')
                {
                    if (isX) moveX.Add(moveCount); else moveY.Add(moveCount);
                    isX = !isX;
                    moveCount = 0;
                }
                if (c == 'F') moveCount++;
            }
            if (isX) moveX.Add(moveCount); else moveY.Add(moveCount);
            var start = moveX[0];
            moveX.RemoveAt(0);
            var differenceX = moveX.Sum() - Math.Abs(x - start);
            var differenceY = moveY.Sum() - Math.Abs(y);
            if (differenceX < 0 || differenceY < 0) return false;
            if ((differenceX % 2) == 1 || (differenceY % 2) == 1) return false;

            var dpX = new bool[10000, moveX.Count + 1];
            for (int i = 0; i < 8000 + 1; i++) for (int j = 0; j < moveX.Count + 1; j++) dpX[i, j] = false;
            dpX[0, 0] = true;
            for (int move = 1; move < moveX.Count + 1; move++)
            {
                for (int sum = 0; sum < 8000 + 1; sum++)
                {
                    if (dpX[sum, move - 1])
                    {
                        dpX[sum, move] = true;
                        dpX[sum + moveX[move - 1], move] = true;
                    }
                }
            }

            var dpY = new bool[10000, moveY.Count + 1];
            for (int i = 0; i < 8000 + 1; i++) for (int j = 0; j < moveY.Count + 1; j++) dpY[i, j] = false;
            dpY[0, 0] = true;
            for (int move = 1; move < moveY.Count + 1; move++)
            {
                for (int sum = 0; sum < 8000 + 1; sum++)
                {
                    if (dpY[sum, move - 1])
                    {
                        dpY[sum, move] = true;
                        dpY[sum + moveY[move - 1], move] = true;
                    }
                }
            }

            return dpX[differenceX / 2, moveX.Count] && dpY[differenceY / 2, moveY.Count];
        }
    }
}


Measured memory_bytes: 75608
n = int(input())
MAX = 10**5
adj = [[[] for u in range(MAX+1)] for t in range(2)]
vis = [[False for u in range(MAX+1)] for t in range(2)]
for i in range(n):
	x, y = map(int,input().split())
	adj[0][x].append(y)
	adj[1][y].append(x)

import sys
sys.setrecursionlimit(4*10**5+1)

def dfs(t,u): # Left, Right, Edges
	vis[t][u] = True

	ct = [0,0,0]
	ct[t] += 1
	for v in adj[t][u]:
		ct[2] += 1
		if not vis[t^1][v]:
			ctv = dfs(t^1,v)

			ct[0] += ctv[0]
			ct[1] += ctv[1]
			ct[2] += ctv[2]

	return ct

ans = 0
for u in range(1,MAX+1):
	if not vis[0][u]:
		L, R, M = dfs(0,u)
		ans += L*R-M//2

print(ans)

Measured memory_bytes: 95668
#include <iostream>
#include <cstdio>
using namespace std;
struct node{int p,l,r;};
node t[25];
int n,h[25],d[25];
void dp1(int now,int de){
  d[now]=de;
  if(t[now].l!=-1) dp1(t[now].l,de+1);
  if(t[now].r!=-1) dp1(t[now].r,de);
}
void dp2(int f,int now,int he){
  h[f]=max(h[f],he);
  if(t[now].l!=-1) dp2(f,t[now].l,he+1);
  if(t[now].l!=-1) if(t[t[now].l].r!=-1) dp2(f,t[t[now].l].r,he+1);
}
int main(){

  int now,tmpl,tmpr,s[25]={0},p[25];
  cin>>n;
  for(int i=0;i<n;i++) t[i].p=t[i].l=t[i].r=p[i]=-1;
  for(int i=0;i<n;i++){
    cin>>now>>tmpl>>tmpr;
    if(tmpl==-1) tmpl=tmpr,tmpr=-1;
    if(tmpl!=-1) s[now]++,t[tmpl].p=now,t[tmpl].r=tmpr;
    if(tmpr!=-1) s[now]++,t[tmpr].p=now;
    t[now].l=tmpl;
  }
  for(int i=0;i<n;i++){
    if(t[i].r!=-1) p[i]=t[i].r;
    else if(t[i].p!=-1) if(t[t[i].p].l!=-1&&t[t[i].p].l!=i) p[i]=t[t[i].p].l;
  }
  int st;
  for(int i=0;i<n;i++) if(t[i].p==-1) st=i;
  dp1(st,0);
  for(int i=0;i<n;i++) dp2(i,i,0);
  for(int i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, ",i,t[i].p,p[i]);
    printf("degree = %d, depth = %d, height = %d, ",s[i],d[i],h[i]);
    if(t[i].p==-1) printf("root\n");
    else if(t[i].l!=-1) printf("internal node\n");
    else printf("leaf\n");
  }
  return 0;
}

Measured memory_bytes: 3232
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {
  
  string n;
  cin >> n;

  string b = n;

  int i = 0;
  for(auto itr = n.rbegin(); itr!=n.rend();itr++)
  {
    b[i] = *itr;
    i++;
  }

  if( n == b) cout<<"Yes";
  else cout << "No";
  
  
    return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

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

int64_t mod = 1000000007 ;

int main(){
    int n ;
    cin >> n ;
    vector<int> t(n) ;
    vector<int> a(n+1) ;
    a.at(n) = 0 ;
    for (int i = 0; i < n; i++)
    {
        cin >> t.at(i) ;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    vector<pair<bool,int> > h(n,pair<bool,int>(make_pair(0,0))) ;
    int64_t ans = 1 ;
    h.at(0).first = 1 ;
    h.at(0).second = t.at(0) ;
    for (int i = 1; i < n; i++)
    {
        if (t.at(i) > t.at(i-1))
        {
            h.at(i).first = 1 ;
            h.at(i).second = t.at(i) ;
        }else
        {
            h.at(i).second = t.at(i) ;
        }
        
        
    }
    for (int i = 0; i < n; i++)
    {
        if (a.at(n-1-i) > a.at(n-i))
        {
            if (h.at(n-1-i).first == 1)
            {
                if (h.at(n-1-i).second != a.at(n-1-i))
                {
                    ans = 0 ;
                    break ;
                }
                
            }else
            {
                h.at(n-1-i).first = 1 ;
                h.at(n-1-i).second = a.at(n-1-i) ;
            }
            
            
            
        }else
        {
            if (h.at(n-1-i).first == 1)
            {
                if (h.at(n-1-i).second > a.at(n-1-i))
                {
                    ans = 0 ;
                    break ;
                }
                
            }else
            {
                h.at(n-1-i).second = min(h.at(n-1-i).second, a.at(n-1-i)) ;
            }
            
            
        }
        
    }
    if (ans != 0)
    {
        for (int i = 0; i < n; i++)
        {
            if (h.at(i).first == 0)
            {
                ans *=  h.at(i).second ;
            }
            
            if (ans > mod)
            {
                ans %= mod ;
            }
            
        }
        
    }
    
    
    cout << ans << endl ;
}


Measured memory_bytes: 4856
H, W=map (int, input().split(' '))
z={}

for i in range(H):
    z[i]=str(input())



for h in range(H):
    for w in range(W):
        if z[h][w:w+1] == "#":
            print('#', end="")
            continue
        p=0
        for dy in [-1, 0, 1]:
            y=h+dy
            if h + dy < 0 or h + dy >= H:
                continue
            for dx in [-1, 0, 1]:
                x=w+dx
                if x < 0 or x >= W:
                    continue
                if x == w and y ==h:
                    continue
                
                if z[y][x:x+1] == "#":
                    p+=1
        print(p,end="")
    print("\n", end="")


Measured memory_bytes: 3444
#include <bits/stdc++.h>
const int maxn=1e5+10,mod=1e9+7;
typedef long long ll;
using namespace std;
int n,m,k,t;
int main()
{
    int i,j;
    //freopen("in.txt","r",stdin);
    int h,w;
    scanf("%d%d%d",&h,&w,&n);
    printf("%d\n",min((h+n-1)/h,(w+n-1)/w));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000000;
const int MAX = 300000;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

//------------------------------------------------------------------------------------------------------------------------------

vector<vector<int>> G;
void dfs(vector<int> &d, int chi, int par = -1) {
    for (auto nv : G[chi]) {
        if (nv == par) {
            continue;
        }
        d[nv] = d[chi] + 1;
        dfs(d, nv, chi);
    }
}

int main(void) {
    int N, u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    G.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> du(N, 0), dv(N, 0);
    dfs(du, u);
    dfs(dv, v);
    int maxd = -1, maxi = 0;
    for (int i = 0; i < N; i++) {
        if (du[i] < dv[i] && maxd < dv[i]) {
            maxd = dv[i];
            maxi = i;
        }
    }
    cout << maxd - 1 << endl;
}

Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
int a[1000];
int main()
{
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 0;i<n;i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    int ans = 0;
    int rst = 1e9;
    for(int i = 0; i < n; i++)
    {
        if(abs(a[i] * n - sum) < rst)
        {
            rst = abs(a[i] * n - sum);
            ans = i;
        }
    }
    cout << ans;
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){
    double D,T,S;
    double X;


    cin>>D>>T>>S;

    X=D/S;

    if(T>=X){
        cout<<"Yes"<<endl;

    }else{
        cout<<"No"<<endl;

    }





    return 0;
}



Measured memory_bytes: 3732
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

long long inputValueLongLong(){
    long long a;
    cin >> a;
    return a;
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    const double PI=3.14159265358979323846;
    // source code
    long long N = inputValueLongLong();
    long long M = inputValueLongLong();
    long long i = 0;
    long long A[M];
    long long shukudai = 0;
    for(i=0;i<M;i++){
        A[i] = inputValueLongLong();
        shukudai += A[i];
    }
    if(shukudai>N){
        cout << -1 << endl;
    }else{
        cout << N-shukudai << endl;
    }


    
    return 0;
}

Measured memory_bytes: 3664
from heapq import heapify, heappushpop
n = int(input())
a = list(map(int, input().split()))
a1 = a[:n]
heapify(a1)
a2 = a[n:2*n]
a3 = [-i for i in a[2*n:]]
heapify(a3)
b1 = [sum(a1)]
b2 = [sum(a3)]
for i in range(n):
    b1.append(b1[-1]+a2[i]-heappushpop(a1, a2[i]))
    b2.append(b2[-1]-heappushpop(a3, -a2[n-i-1])-a2[n-i-1])
ans = b1[0]+b2[n]
for i in range(n+1):
    ans = max(ans, b1[i]+b2[n-i])
print(ans)

Measured memory_bytes: 42684