akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        while(true){
            
            int a=scan.nextInt();
            String s=scan.next();
            int b=scan.nextInt();
            if(s.equals("?")) break;
            if(s.equals("+")) System.out.println(a+b);
            else if(s.equals("-")) System.out.println(a-b);
            else if(s.equals("*")) System.out.println(a*b);
            else if(s.equals("/")) System.out.println(a/b);
        }
        
    }
}


Measured memory_bytes: 26304
A, B, C, X = [int(input()) for _ in range(4)]

ans = 0
for num500 in range(A+1):
    for num100 in range(B+1):
        for num50 in range(C+1):
            if 500*num500 + 100*num100 + 50*num50 == X:
                ans += 1
print(ans)


Measured memory_bytes: 2940
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

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


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var nm = Reads();
            var n = nm[0];
            var m = nm[1];
            long[] a = new long[n],b=new long[n],c=new long[m],d=new long[m];

            
            for (int i = 0; i < n; i++)
            {
                var ab = Reads();
                a[i] = ab[0];
                b[i] = ab[1];
            }
            for (int i = 0; i < m; i++)
            {
                var cd = Reads();
                c[i] = cd[0];
                d[i] = cd[1];
            }
            for (int i = 0; i < n; i++)
            {
                long ans = long.MaxValue;
                long memo = 0;
                for (int j = 0; j < m; j++)
                {
                    if (Math.Abs(a[i] - c[j]) + Math.Abs(b[i] - d[j]) < ans)
                    {
                        memo = j+1;
                        ans = Math.Abs(a[i] - c[j]) + Math.Abs(b[i] - d[j]);
                    }
                }
                WriteLine(memo);
            }
            
            

            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 19056
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end 
def mtree(x,d,p)
  ret = []
  @md = d if(d>@md)
  if(@data[x][1] > 0)
    @data[x][2..(@data[x][1]+1)].each do|nx|
      ret.push(nx)
      (mtree(nx,d+1,x))
    end
    @tab.push([x,d,p,ret])
  else
    @tab.push([x,d,p,[]])
  end
end
@md = 0
@tab = []
n = inp[0]
@data = na(n)
r = []
n.times do|d|
  @data[d] = inp
end
@data.sort!
n.times do|d|
  r.concat(@data[d][2..(@data[d][1]+1)]) if(@data[d][1] > 0)
end
if(r != [] and r != nil)
  x = scount(r).index(0)
else
  x = 0
end 
mtree(x,0,-1)
@tab.sort!
n.times do |d|
  j = "leaf"
  j = "internal node" if(@tab[d][3].size!=0)
  j = "root" if(@tab[d][1] == 0)
  puts "node #{@tab[d][0]}: parent = #{@tab[d][2]}, depth = #{@tab[d][1]}, #{j}, #{@tab[d][3]}"
end
=begin

=end

  

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

typedef vector<int> vi;
typedef pair<int, int> pi;

int N, M;
pi del_pth;
vector<bool> vis;
vector<pi> P;
vector<vi> G;

void dfs(int s) {
	if (vis[s])
		return;
	vis[s] = true;
	for (int i = 0; i < (int)G[s].size(); ++i) {
		int t = G[s][i];
		pi pth = (s < t) ? make_pair(s, t) : make_pair(t, s);
		if (pth != del_pth)
			dfs(t);
	}
}

bool check(void) {
	bool f = false;
	for (int i = 1; i <= N; ++i) {
		if (vis[i] == false) {
			f = true;
			break;
		}
	}
	return f;
}

int main(void) {
	cin >> N >> M;
	P.resize(M);
	G.resize(N + 1);

	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		P[i] = make_pair(a, b);
		G[a].push_back(b);
		G[b].push_back(a);
	}

	int ans = 0;
	for (int i = 0; i < M; ++i) {
		del_pth = P[i];
		vis.clear();
		vis.resize(N + 1, false);
		dfs(1);
		bool res = check();
		if (res)
			++ans;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    int hi;
    int ans = 0;

    cin >> n >> k;

    for(int i = 0; i < n; ++i)
    {
        cin >> hi;
        ans += hi >= k ? 1 : 0;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define rem(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;

#define max 1000000000000000000

int main() {
	ld a,b,ans;
	ll ansll;
	cin >> a >> b;
	ans = a * b;
	ansll = floorl(ans);
	
	cout << ansll << '\n';
	return 0;

}

Measured memory_bytes: 3784
N, M, x, y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

for i in range(x + 1, y + 1):
  if (max(X) < i and i <= min(Y)):
    print('No War')
    exit()
else:
  print('War')

Measured memory_bytes: 38384
#include<iostream>
using namespace std;
int main()
{
	int n,cnt=0;
	cin>>n;
	for(int i=1,a;i<=n;++i)
		cin>>a,cnt+=(a!=i);
	if(cnt==2||cnt==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
 
using namespace std;

int arr[2008];

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

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

    sort(arr, arr+n);


    int c;
    long long ans = 0;
    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            c = arr[i] + arr[j];
            ans += (lower_bound(arr, arr+n, c) - arr - 1) - j;
            // cout << i << " " << j << " " << ans << endl;
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
deque<in> b;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  in a;
  forn(z,n){
    cin>>a;
    if(z%2==0)
      b.push_back(a);
    else
      b.push_front(a);
  }
  if(n%2==0){
    forn(z,n){
      cout<<b.front()<<" ";
      b.pop_front();
    }
  }
  else{
    forn(z,n){
      cout<<b.back()<<" ";
      b.pop_back();
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>

using namespace std;
typedef uint32_t it;

int main()
{
        it n, w;
        cin >> n >> w;
        vector<it> vi(n+1), wi(n+1);
        vector<it> table(w+1, 0);

        for(it i = 1; i <= n; ++i){
                scanf("%u %u", &vi[i], &wi[i]);
        }

        for(it i = 1; i <= n; ++i){
//#pragma omp parallel for
                for(it j = w-wi[i]; j >= 1; --j){
                        if(table[j] == 0)
                                continue;
                        if(table[j] + vi[i] > table[j + wi[i]])
                                table[j + wi[i]] = table[j] + vi[i];
                }
                if(table[wi[i]] < vi[i])
                        table[wi[i]] = vi[i];
        }

        cout << *max_element(begin(table), end(table)) << endl;

        return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
#define rep(i,n) for(lint (i) = 0;(i) < (lint)(n);(i)++)
#define repInRange(i,start,end) for(lint (i) = (start);(i) < (end);++(i))
using lpair = pair<lint,lint>;
using Vecint = vector<lint>;
using Llist = list<lint>;

ll pow(ll k,ll l) {
	ll ret = 1;
	rep(i,l) {
		ret *= k;
	}
	return ret;
}

template <typename T>
T sum(vector<T> vec) {
	ll ret = 0;
	rep(i,vec.size()) {
		ret += vec.at(i);
	}
	return ret;
}

void Main() {
	lint N,A,B,c = 0;
	cin >> N >> A >> B;
	if (A == 0 && B == 0) {
		cout << 0 << '\n';
		return;
	}
	c = (N/(A+B))*A;
	if ((N%(A+B)) >= A) {
		c += A;
	} else {
		c += N%(A+B);
	}
	cout << c << '\n';
}

signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	Main();
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := scanInt(), scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}

	const mod = 1000000007
	cnt1, cnt2 := 0, 0
	for i := range a {
		for j := range a {
			if a[i] > a[j] {
				cnt1++
				if j > i {
					cnt2++
				}
			}
		}
	}
	ans := (k * (k - 1) / 2 % mod) * cnt1
	ans %= mod
	ans += cnt2 * k
	ans %= mod
	fmt.Println(ans)
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll sum[200005], b[200005], c[200005];

// Segment Tree
constexpr int MAX_N = 1 << 17;
constexpr int INI = 0;
int num, dat[2 * MAX_N - 1];

// まず呼ぶ
void init(int n_) {
	num = 1;
	while (num < n_) num *= 2;
	for (int i = 0; i < 2 * num - 1; ++i) dat[i] = INI;
}

// k番目(0-indexed)の値をaに更新
void update(int k, int a) {
	k += num - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = dat[2 * k + 1] + dat[2 * k + 2];
	}
}

// [a, b)の値を取得
// kはノードのインデックス
// [left, right)はノードkが対応する範囲
// query(a, b, 0, 0, num)で呼ぶ.
int query(int a, int b, int k, int left, int right) {
	if (right <= a || b <= left) return INI;
	if (a <= left && right <= b) return dat[k];
	int vleft = query(a, b, 2 * k + 1, left, left + (right - left) / 2);
	int vright = query(a, b, 2 * k + 2, left + (right - left) / 2, right);
	return vleft + vright;
}

int main() {
	int n; ll k; cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		ll a; cin >> a;
		sum[i] = a;
	}
	for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];
	for (int i = 0; i <= n; ++i) b[i] = sum[i] - i*k;
	sort(b, b + n + 1);
	int pos = 1;
	c[0] = b[0];
	for (int i = 1; i <= n; ++i) {
		if (c[pos - 1] == b[i]) continue;
		c[pos++] = b[i];
	}
	for (int i = 0; i <= n; ++i) {
		int lo = -1, hi = pos;
		while (hi - lo > 1) {
			int mid = lo + (hi - lo) / 2;
			if (c[mid] <= sum[i] - i*k) lo = mid;
			else hi = mid;
		}
		b[i] = lo;
	}
	init(pos);
	ll ans = 0;
	for (int i = 0; i <= n; ++i) {
		ans += (ll)query(0, b[i] + 1, 0, 0, num);
		update(b[i], query(b[i], b[i] + 1, 0, 0, num) + 1);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	string s, out;
	out="";
	cin>> s;
	for(int i=0; i<s.length(); i+=2){
		out+=s[i];
	}
	cout<<out;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ks ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pa;
const int maxn=1e6+177;
const ll mod=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
template<class T>inline void read(T &res){
    char c;T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
void wenjian(){freopen("concatenation.in","r",stdin);freopen("concatenation.out","w",stdout);}
void tempwj(){freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){a %= mod;ll ans = 1;while(b){if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}
int a[maxn];
int main(){


    int n;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);
    }
    int ans=0;
    for(int i=1;i<=n;i=i+2){

        if(a[i]%2!=0){
            ans++;
        }
    }
    printf("%d\n",ans);

}


Measured memory_bytes: 3756
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct thing
{
	long long w;int v,id;
	friend bool operator < (thing a,thing b){return a.w*b.v==a.v*b.w?a.v>b.v:a.w*b.v<a.v*b.w;}
}p[51];
int n,x,d,m[51],f[51],siz[51],used[51],ans;
long long sum[51];
vector<int>E[51];
void dfs(int v)
{
	siz[v]=1,sum[v]=m[v];
	for(auto u:E[v])
	{
		dfs(u);
		sum[v]+=sum[u];
		siz[v]+=siz[u];
	}
	p[v]=thing{sum[v],siz[v],v};
}
long long dp[125010],q[125010][2],h,t;
int main()
{
	scanf("%d %d %d %d",&n,&x,&d,&m[1]);
	for(int i=2;i<=n;++i)scanf("%d %d",&m[i],&f[i]),E[f[i]].push_back(i);
	dfs(1);
	sort(p+1,p+1+n);
	int sum=0;
	for(int i=1;i<=n;++i)sum+=p[i].v*min(n,p[i].id==1?0x3f3f3f3f:d);
	dp[0]=0;
	memset(dp+1,0x3f,sum<<3);
	for(int i=1;i<=n;++i)
	{
		int num=min(n,p[i].id==1?0x3f3f3f3f:d);
		for(int j=0;j<p[i].v;++j)
		{
			h=1,t=0;
			for(int k=j,c=0;k<=sum;k+=p[i].v,++c)
			{
				long long va=dp[k]-c*p[i].w;
				while(h<=t&&q[t][0]>va)--t;
				q[++t][0]=va,q[t][1]=c;
				while(h<=t&&q[h][1]+num<c)++h;
				dp[k]=q[h][0]+c*p[i].w;
			}
		}
	}
	for(int i=0;i<=sum;++i)
	{
		if(x<dp[i])continue;
		int rem=x-dp[i];
		int cur=i;
		for(int j=1;j<=n;++j)
		{
			int now=p[j].id==1?0x3f3f3f3f:max(d-n,0);
			now=min(now,(int)(rem/p[j].w));
			cur+=now*p[j].v;
			rem-=now*p[j].w;
		}
		ans=max(ans,cur);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;

char a[100000][8];

int main()
{
    int x,y;
    while(~scanf("%d%d",&x,&y))
    {
        int t = y*1800 + x*100;
        int q = pow(2,y)+0.5;
        int ans = t*q;
        printf("%d\n",ans);
    }
    return 0;
}


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

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	set<int> s;
	for(int i=0;i<k;i++){
		s.insert(a[i]);
	}
	int res=1,flag=1;
	int b[n],c=1;
	memset(b,0,sizeof(b));
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1]) c++;
		else c=1;
		if(c>=k) b[i-k+1]=1;
	}
	if(b[0]) flag=0;
	for(int i=0;i<n-k;i++){
		if(a[i]!=*(s.begin()) || a[i+k]<*(s.rbegin())){
			if(b[i+1]){
				if(flag){
					res++;
					flag=0;
				}
			}
			else res++;
		}
		s.erase(a[i]);
		s.insert(a[i+k]);
	}
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 11136
from typing import Union
import sys
from operator import itemgetter

Num = Union[int, float]


class FenwickTree:
    def __init__(self, size: int):
        self.size = size
        self.bit = [0] * (self.size + 1)
    
    def add(self, k: int, x: Num) -> None:
        """
        (0-index で) k 番目の要素に x をたす。
        >>> b = FenwickTree(5)
        >>> b.add(0, 10)
        >>> b.bit
        [0, 10, 10, 0, 10, 0]
        """
        if not 0 <= k < self.size:
            raise IndexError(f"FenwickTree.add(): size is {self.size}. accessed [{k}]")
        k += 1    # 1-index
        while k <= self.size:
            self.bit[k] += x
            LSB = k & (-k)
            k += LSB
    
    def _accum_sum(self, k: int) -> Num:
        """ (1-index, 内部関数) bit の 1 ~ k 番目の要素の和を求める。"""
        s = 0
        while k > 0:
            s += self.bit[k]
            LSB = k & (-k)
            k -= LSB
        return s
    
    def sum(self, l: int, r: int) -> Num:
        """
        (0-index で) [l, r) 区間の和を求める。
        >>> b = FenwickTree(5)
        >>> b.add(1, 10)
        >>> b.add(2, 20)
        >>> b.sum(1, 3)
        30
        """
        if not 0 <= l <= r <= self.size:
            raise IndexError(f"FenwickTree.sum(): size is {self.size}. got slice is [{l}:{r}]")
        # 0-index の数列における [l]...[r-1] の閉区間を計算。1-index なら [l+1]...[r]。
        return self._accum_sum(r) - self._accum_sum(l)



def input(): return sys.stdin.readline().rstrip()

def mi(): return map(int, input().split())

def mi_0(): return map(lambda x: int(x)-1, input().split())


def solve(n, q, interval, query):
    """
    [s, t] なる点を含むリスト interval
    [l, r(, query-number)] (0-index) なるクエリを q 個含むリスト query。l <= s and t <= r なる点の個数は何個か？
    """
    query_to_ans = [-1] * q
    query.sort(key=itemgetter(0))
    interval.sort(key=itemgetter(0))
    ft = FenwickTree(5 * 10 ** 5 + 5)
    # main
    for l, r, query_num in reversed(query):
        # l 以上のものを全て処理対象に入れる
        while interval and l <= interval[-1][0]:
            _, t = interval.pop()
            ft.add(t, 1)
        query_to_ans[query_num] = (r - l + 1) - ft.sum(0, r+1)
    # output
    for ans in query_to_ans:
        print(ans)



def main():
    n, q = mi()
    L = tuple(mi())
    prev = dict()
    intervals = []
    for i in range(n):
        if L[i] not in prev:
            prev[L[i]] = i
        else:
            intervals.append((prev[L[i]], i))
            prev[L[i]] = i
    query = []
    for i in range(q):
        l, r = mi_0()
        query.append((l, r, i))
    solve(n, q, intervals, query)
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 233908
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

a = arr_data[0][0]
b = arr_data[0][1]

if a==b:
    
    print("=")
elif a<b:
    
    print("<")
    
elif a>b:
    
    print(">")


Measured memory_bytes: 3064
N = gets.to_i
A = gets.split.map(&:to_i)

H = Hash.new(0)

N.times do |i|
  H[A[i] - 1] += 1
  H[A[i]    ] += 1
  H[A[i] + 1] += 1
end

puts H.values.sort[-1]

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

int main(){
    float  n,t,a;

    cin >>n>>t>>a;
    vector<float> H(n);

    for (float i = 0; i < n;i++){
        cin >> H[i];
    }
    float min = 999999;
    float pos = -1;

    for(float i = 0; i < n; i++){
        float tmp = t-H[i]*0.006;
        float dif = abs(a-tmp);
        if(min > dif){
            min = dif;
            pos = i;
        }
    }
    cout << pos + 1 <<endl;

}


Measured memory_bytes: 256
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ = Printf.printf "%d\n" @@ if n * m = 1 then 1 else if n = 1 || m = 1 then n * m - 2 else if n = 2 || m = 2 then 0 else (n - 2) * (m - 2)

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

int main(){
  int a, b;
  cin >> a >> b;
  if (a < b){
    for (int i = 0; i < b; i++){
      cout << a;
    }
  }
  else
  {
    for (int i = 0; i < a; i++){
      cout << b;
    }
  }
  cout << endl;
}

Measured memory_bytes: 3448
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

string AL = "abcdefghijklmnopqrstuvwxyz";
string ALR = "zyxwvutsrqponmlkjihgfedcba";
int N = AL.size();

int main(){

    string s; cin >> s;

    if(s.size() < 26){
        for(int i=0; i<N; i++){
            if(s.find(AL[i]) == string::npos){
                s += AL[i];
                cout << s << endl;
                break;
            }
        }
    }
    else if(s == ALR){
        cout << -1 << endl;
    }
    else{
        string temp = "";
        for(int i=N-1; i>0; i--){
            temp += s[i];
            // cout << temp << endl;
            if(s[i] > s[i-1]){
                char temp2 = s[i-1];
                s.pop_back();
                s.pop_back();
                char min = 'z';
                for(int j=0; j<temp.size(); j++){
                    if(min > temp[j] && temp[j] > temp2){
                        min = temp[j];
                    }
                }
                s.push_back(min);
                cout << s << endl;
                break;
            }
            s.pop_back();
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n, index;
		String s;
		HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
		Integer count;
		String[] verdict = {"AC", "WA", "TLE", "RE"}; 

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());
		for(index = 1; index <= n; index++) {
			s = br.readLine();
			count = hashMap.getOrDefault(s, 0);
			hashMap.put(s, ++count);
		}
		s = verdict[0];
		count = hashMap.getOrDefault(s, 0);
		System.out.println(s+" x "+count);
		s = verdict[1];
		count = hashMap.getOrDefault(s, 0);
		System.out.println(s+" x "+count);
		s = verdict[2];
		count = hashMap.getOrDefault(s, 0);
		System.out.println(s+" x "+count);
		s = verdict[3];
		count = hashMap.getOrDefault(s, 0);
		System.out.println(s+" x "+count);
	}
}


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

//bool comp(pair<int,int> a, pair<int,int> b){return a.second < b.second;}

int main(void){
    
    string S,T;
    cin >> S >> T;
    if(T.size() > S.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    string c;
    string memo;
    vector<string> C;
    //起点を探すループ
    //cout << S.size() - T.size() << endl;
    for(int i = 0; i < S.size() - T.size()+1;i++){
        c = "";
        for(int k = 0; k < i;k++){
                if(S[k]!='?')c += S[k];
                else c += "a";
                //cout << c << endl;
            }
            //cout <<"#############"<<endl;
        
        for(int j = 0; j < T.size();j++){
            
            //cout << S[i+j] <<" "<<T[j]<< endl;
            if(S[i+j]!=T[j]&&S[i+j]!='?')break;
            
            if(S[i+j]==T[j]||S[i+j]=='?') c += T[j]; 
            //else if(S[i+j]=='?') c += "a";
            //cout << c << endl;
            if(j == T.size()-1){
                for(int k = i + j + 1; k < S.size();k++ ){
                    if(S[k]!='?')c += S[k];
                    else c += "a";
                }
                
                
                //cout << c << endl;
                C.push_back(c);
            }
        }
        
        //cout <<"-------------"<<endl;
        
        
    }
    
    sort(C.begin(),C.end());
    if(C.size()!=0)cout << C[0] << endl;
    else cout << "UNRESTORABLE" << endl;
        
        
    return 0;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;
const int maxn=1e5+10;
char str[maxn];
int main()
{
    scanf("%s",str+1);
    int len=strlen(str+1);
    int ans=0;
    for(int i=1;i<=len/2;i++)
    {
        if(str[i]!=str[len-i+1]) ans++;
    }
    printf("%d\n",ans);
}


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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod =  1e9 + 7;
const int N = 1e6;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
*/

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}



int main()
{
	#ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
   	ll n;
   	cin>>n;
   	ll a[n+5][n+5]  = {0};

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

   	ll dp[1<<n] = {0};
   	dp[0] = 1;
   	for(int i=0;i<(1<<n);i++)
   	{
   		int x = __builtin_popcount(i);

   		for(int j=0;j<n;j++)
   		{
   			if(!(i&(1<<j)) && a[x][j]==1)
   			{
   				dp[i|1<<j] = (dp[i|1<<j] + dp[i])%mod;
   			}
   		}
   	}

   	cout << dp[(1<<n) - 1]%mod << "\n";
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i=0;i<N;i++){
    cin >> s.at(i);
    sort(s.at(i).begin(),s.at(i).end());
  }
  sort(s.begin(),s.end());
  long long int ans=0;
  string t;
  t=s.at(0);
  long long int count=1;
  for(int i=1;i<N;i++){
    if(s.at(i)==t){
      count++;
    }else{
      if(count==1){
        t=s.at(i);
      }else{
        ans+=count*(count-1)/2;
        count=1;
        t=s.at(i);
      }
    }
      
  }
  cout << ans+count*(count-1)/2 << endl;
}

Measured memory_bytes: 7296
'use strict'

function isZero(arr) {
    for (let elem of arr) {
        if (elem !== 0) {
            return false;
        }
    }
    return true;
}
function main(input) {
    const tmp = Array.from(input.split('\n'));
    const N = parseInt(tmp[0], 10);
    const h = tmp[1].split(' ').map((elem) => parseInt(elem, 10));

    let count = 0;
    while (!isZero(h)) {
        const maxVal = h.reduce((max, elem) => Math.max(max, elem));
        const maxValStartInd = h.indexOf(maxVal);
        let maxValEndInd = maxValStartInd;
        while (h[maxValEndInd + 1] === maxVal) {
            maxValEndInd++;
        }
        const maxValRange = Array.from(new Array(maxValEndInd - maxValStartInd + 1).fill(0).map((elem, i) => i + maxValStartInd));

        for (let maxValInd of maxValRange) {
            h[maxValInd]--;
        }
        count++;
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

typedef long long ll;

void bubble(vector<pair<char,int> > &v,int n){
    for(int i=0;i<n;i++){
        for(int j=0;j<n-i-1;j++){
            if(v[j].second>v[j+1].second)swap(v[j],v[j+1]);
        }
    }
}

void select(vector<pair<char,int> > &v,int n){
    for(int i=0;i<n;i++){
        int mij=i,mi=v[i].second;
        for(int j=i;j<n;j++){
            if(mi>v[j].second){
                mi=v[j].second;
                mij=j;
            }
        }
        swap(v[i],v[mij]);
    }
}


int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<char,int> > card(n);
    string s;
    for(int i=0;i<n;i++){
        cin >> s;
        card[i].first=s[0];
        card[i].second=s[1]-'0';
    }
    vector<pair<char,int> > bs(card);
    vector<pair<char,int> > ss(card);

    bubble(bs,n);
    select(ss,n);

    for(int i=0;i<n;i++)cout << (char)bs[i].first << bs[i].second << (i!=n-1?" ":"\n");
    cout << "Stable\n";
    for(int i=0;i<n;i++)cout << (char)ss[i].first << ss[i].second << (i!=n-1?" ":"\n");
    cout << (bs==ss?"Stable":"Not stable") << endl;
}



Measured memory_bytes: 3212
integer N
integer,allocatable,dimension(:)::H
integer DP(10**5)
read*,N
allocate(H(N))
read*,H

DP(1)=0
DP(2)=abs(H(2)-H(1))
if(N==2)then
  print"(i0)",DP(N)
  STOP
endif
do i=3,N
  DP(i)=min(DP(i-1)+abs( H(i)-H(i-1) ),DP(i-2)+abs( H(i)-H(i-2) ) )
end do
print"(i0)",DP(N)
end

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll unsigned long long int
#define mod 998244353
using namespace std;
ll power(ll x, ll y, ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
ll d[100005];
map <ll,ll> mp;
int main(){
cin>>n;
for(ll k=1;k<=n;k++){
    cin>>d[k];
    mp[d[k]]++;
}
    ll ind=0;
    if(d[1]!=0)
        ind=1;
        sort(d+1,d+n+1);
for(ll k=2;k<=n;k++)
    if((d[k]==d[k-1] || d[k]-1==d[k-1]) && d[k]!=0 && d[k]<=n-1)
    continue;
    else{
        ind=1;
        break;
    }
    if(ind){
        cout<<0;
        return 0;
    }
    ll ans=1;
vector<ll> v;
for(ll k=0;k<=d[n];k++){
    v.push_back(mp[k]%mod);
}
for(ll k=0;k<v.size()-1;k++){
 ll a=v[k]%mod;
   ll b=v[k+1]%mod;
    ll  h=power(a%mod,b%mod,mod)%mod;
    ans=((ans%mod)*(h%mod))%mod;
}
cout<<ans%mod;
return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c;
  cin>>a>>b>>c;
  if(a<=c&&c<=b){
cout<<"Yes"<<endl;
}else{
  cout<<"No"<<endl;
}

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 101
using namespace std;
const int INF = 1LL<<55;
int n,d;
vector<int> A[N];
int Sum[N];

int getMax(){return *max_element(Sum,Sum+n);}
int getMin(){return *min_element(Sum,Sum+n);}

int getIdx(){
  int sa = INF;
  int res  = -1;
  for(int i=0;i<n;i++){
    if(A[i].empty()) continue;
    int sum = Sum[i] + A[i].back();
    Sum[i]+=A[i].back();
    int mn = getMin();
    Sum[i]-=A[i].back();
    if(sum - mn > d)continue;
    if(sum - mn < sa) sa = sum - mn, res = i;
  }
  return res;
}

bool clear(){
  for(int i=0;i<n;i++) if(A[i].size())return 0;
  return 1;
}

bool solve(){
  memset(Sum,0,sizeof(Sum));
  while(!clear()){
    int idx = getIdx();
    if(idx == -1) return 0;
    Sum[idx] += A[idx].back(); A[idx].pop_back();
  }
  return 1;
}

signed main(){
  while(1){
    cin>>n>>d;
    if(!n && !d) break;

    for(int i=0;i<n;i++){
      int k;
      cin>>k;
      A[i].resize(k);
      for(int j=0;j<k;j++)cin>>A[i][j];
      reverse(A[i].begin(),A[i].end());
    }
    cout<<(solve()?"Yes":"No")<<endl;
  }

  return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  vector<ll>num(100004, 0);
  int N;
  cin >> N;
  ll S = 0;
  for (int i = 0; i < N; i ++) {
    int a;
    cin >> a;
    num[a] ++;
    S += (ll)a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i ++) {
    int b, c;
    cin >> b >> c;
    ll kj = (ll)c - b;
    S += (kj * num[b]);
    cout << S << endl;
    num[c] += num[b];
    num[b] = 0;
  }
}



Measured memory_bytes: 3856
#include <iostream>
#define MAX 500000
using namespace std;

int nodes[MAX];
int n;

int left(int i){ return i*2; }
int right(int i){return i*2 + 1;}
int parent(int i){return i/2; }

void max_heapify(int key){
  int l = left(key);
  int r = right(key);
  int largest;
  if(l <= n && nodes[l] > nodes[key]){
    largest = l;
  }else{
    largest = key;
  }
  if(r <= n && nodes[r] > nodes[largest]){
    largest = r;
  }

  if(largest != key){
    swap(nodes[key],nodes[largest]);
    max_heapify(largest);
  }
}

void build_maxheap(){
  for(int i = n/2; i>=1; i--){
    max_heapify(i);
  }
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>nodes[i];
  }

  build_maxheap();

  for(int i=1;i<=n;i++){
    printf(" %d",nodes[i]);
  }
  printf("\n");
}

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

T = [1] * (N+1)

for i in range(2, N+1):
    c = 1
    while i * c <= N:
        T[i * c] += 1
        c += 1

ans = 0

for i in range(1, N+1):
    ans += i * T[i]

print(ans)


Measured memory_bytes: 145852
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <cstring>
using namespace std;

bool cells[502][502];
int lft[502][502];

int main() {
    ios::sync_with_stdio(false);
    int H, W;
    while (cin >> H >> W, H) {
        char c;
        for (int i=1; i<=H; ++i) {
            for (int j=1; j<=W; ++j) {
                cin >> c;
                cells[i][j] = c == '*';
            }
        }
        memset(lft, 0, sizeof lft);
        for (int i=1; i<=H; ++i) {
            for (int j=1; j<=W; ++j) {
                lft[i][j] = (cells[i][j] ? 0 : lft[i][j-1] + 1);
            }
        }
        int ans = 0;
        for (int i=1; i<=W; ++i) {
            stack<pair<int,int> > st;
            for (int j=1; j<=H+1; ++j) {
                int t = -1;
                while ( ! st.empty() && lft[j][i] < st.top().first) {
                    ans = max(ans, st.top().first * (j - st.top().second));
                    t = st.top().second;
                    st.pop();
                }
                if (0 < t) {
                    st.push(make_pair(lft[j][i], t));
                } else {
                    st.push(make_pair(lft[j][i], j));
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2440
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li];
int cev;
string s;
vector<int> v[li];

inline int dfs(int node){
	int cevv=0;
	if(v[node].size()==0)return 0;
	if(~dp[node])return dp[node];
	for(int i=0;i<(int)v[node].size();i++){
		cevv=max(cevv,dfs(v[node][i])+1);
	}
	return dp[node]=cevv;
}

int main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		v[x].pb(y);
	}
	FOR{
		cev=max(cev,dfs(i));
	}
	printf("%d\n",cev);
	return 0;
}



Measured memory_bytes: 22576
h, w, n = [int(i) for i in input().split()]
A = [0 for _ in range(n)]
B = [0 for _ in range(n)]
cnt = {}


for i in range(n):
	a, b = [int(j) for j in input().split()]
	if a > 1 and b > 1 and a < h and b < w:
		if "{} {}".format(a, b) not in cnt.keys():
			cnt["{} {}".format(a, b)] = 0
		cnt["{} {}".format(a, b)] += 1
	if a > 2 and b > 2 and a <= h and b <= w:	
		if "{} {}".format(a-1, b-1) not in cnt.keys():
			cnt["{} {}".format(a-1, b-1)] = 0
		cnt["{} {}".format(a-1, b-1)] += 1
	if a > 2 and b > 1 and a <= h and b < w:	
		if "{} {}".format(a-1, b) not in cnt.keys():
			cnt["{} {}".format(a-1, b)] = 0
		cnt["{} {}".format(a-1, b)] += 1
	if a > 2 and b > 0 and a <= h and b < w-1:
		if "{} {}".format(a-1, b+1) not in cnt.keys():
			cnt["{} {}".format(a-1, b+1)] = 0
		cnt["{} {}".format(a-1, b+1)] += 1
	if a > 1 and b > 2 and a < h and b <= w:
		if "{} {}".format(a, b-1) not in cnt.keys():
			cnt["{} {}".format(a, b-1)] = 0
		cnt["{} {}".format(a, b-1)] += 1
	if a > 0 and b > 0 and a < h-1 and b < w-1:
		if "{} {}".format(a+1, b+1) not in cnt.keys():
			cnt["{} {}".format(a+1, b+1)] = 0
		cnt["{} {}".format(a+1, b+1)] += 1
	if a > 0 and b > 1 and a < h-1 and b < w:
		if "{} {}".format(a+1, b) not in cnt.keys():
			cnt["{} {}".format(a+1, b)] = 0
		cnt["{} {}".format(a+1, b)] += 1
	if a > 1 and b > 0 and a < h and b < w-1:
		if "{} {}".format(a, b+1) not in cnt.keys():
			cnt["{} {}".format(a, b+1)] = 0
		cnt["{} {}".format(a, b+1)] += 1
	if a > 0 and b > 2 and a < h-1 and b <= w:
		if "{} {}".format(a+1, b-1) not in cnt.keys():
			cnt["{} {}".format(a+1, b-1)] = 0
		cnt["{} {}".format(a+1, b-1)] += 1

count = [0 for i in range(10)]
for i in cnt.values():
	count[i] += 1
count[0] =  (h-2)*(w-2) - len(cnt)

for i in count:
	print(i)





Measured memory_bytes: 128432
# Problem:
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(selectNum, snakeLongList):
    result = 0
    sortedSnakeLongList = sorted(snakeLongList, reverse=True)
    for j in range(0, selectNum, +1):
        result = result + sortedSnakeLongList[j]
    # algorithm
    return result


if __name__ == "__main__":
    _, K = MI()
    LongI = LI()
    print("{}".format(solver(K, LongI)))


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

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int v[n];
	memset(v,0,sizeof(v));
	vector<int> adj[n];
	int x,y;
	int i,j;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int ans=0;
	for(i=0;i<n;i++)
	{
		if(v[i]==0)
		{
			ans++;
			queue<int> q;
			q.push(i);
			v[i]=1;
			while(q.size())
			{
				x=q.front();
				q.pop();
				for(int j:adj[x])
				{
					if(v[j]==0)
					{
						q.push(j);
						v[j]=1;
					}
				}
			}
		}
	}
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 9204
fun main(args: Array<String>) {
    abc000X()
}

fun abc000X() {
    val n = readLine()!!.toInt()
    val h = readLine()!!.split(" ").map(String::toInt)

    var mem = -2
    for (i in 0 until n) {
        if (mem == -2) {
            mem = h[i]
            continue
        }
        var diff = h[i] - h[i - 1]
        
        if (diff == 0) {
        } else if (diff > -1) {
            mem = 0
        } else if (diff == -1 && mem == -1) {
            println("No")
            return
        } else if (diff == -1) {
            mem = -1
        } else {
            println("No")
            return
        }
    }

    println("Yes")
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int sum = 0;
    int arr[N];
    for (int i = 0; i < N; i++) {
	cin >> arr[i];
	sum += arr[i];
    }
    int average = ((double) sum / N - (int) sum / N) >= 0.5 ? sum / N + 1 : sum / N;
    sum = 0;
    for (int i = 0; i < N; i++) sum += pow(arr[i] - average, 2);
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
  vector<char> s;
  vector<char> t;
  string a, b;
  cin >> a;
  cin >> b;

  bool ans = false;

  for (char x : a) {
    s.push_back(x);
  }
  for (char x : b) {
    t.push_back(x);
  }

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  for (int i = 0; i < b.length(); i++) {
    if (s[i] < t[i]) {
      ans = true;
      break;
    } else if (s[i] > t[i]) {
      break;
    }
  }

  // for (char x : s) {
  //   cout << x;
  // }
  // cout << "" << endl;
  //
  // for (char x : t) {
  //   cout << x;
  // }
  // cout << "" << endl;

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


Measured memory_bytes: 256
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
L = []
for i in range(N):
    a, b = map(int, input().split())
    L.append((a, b))
L = sorted(L, key=lambda x: x[0])

n = 0
ans = 0
for i in range(N):
    if n + L[i][1] <= M:
        ans += L[i][1] * L[i][0]
        n += L[i][1]
    else:
        ans += (M-n) * L[i][0]
        n = M
        break
print(ans)


Measured memory_bytes: 24584
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m = map(int,input().split())
S = sum(map(int,input().split()))
if n >= S:
  print(n-S)
else:
  print(-1)

Measured memory_bytes: 10116
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        a: f64,
        b: f64,
        x: f64,
    }
    let s = x / a;
    let t: f64 = if s < a * b / 2.0 {
        let w = 2.0 * s / b;
        b.atan2(w)
    } else {
        let h = (a * b - s) * 2.0 / a;
        h.atan2(a)
    };
    let d = (t / (2.0 * std::f64::consts::PI)) * 360.0;
    println!("{}", d);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <limits.h>
using namespace std;
typedef long long LL;
const int N=200;

int n,s,a[N];

int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		scanf("%d",&a[i]);
		s+=a[i];
	}
	int ans=0;
	for(int i=1;i<n;i++) {
		if(abs(a[i]*n-s)<abs(a[ans]*n-s)) {
			ans=i;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 100000;
struct edge{
	int to;
	edge *nxt;
}edges[MAXN + 5], *adj[MAXN + 5], *ecnt = &edges[0];
void addedge(int u, int v) {
	edge *p = (++ecnt);
	p->to = v, p->nxt = adj[u], adj[u] = p;
}
struct node{
	int ind; int dep;
}a[MAXN + 5];
bool operator < (node a, node b) {
	return a.dep < b.dep;
}
int N, K;
int fa[MAXN + 5], vis[MAXN + 5], rev[MAXN + 5];
void dfs(int rt) {
	for(edge *p=adj[rt];p!=NULL;p=p->nxt) {
		a[p->to].dep = a[rt].dep + 1;
		dfs(p->to);
	}
}
void dfs2(int rt) {
	if( vis[rt] ) return ;
	vis[rt] = true;
	for(edge *p=adj[rt];p!=NULL;p=p->nxt)
		dfs2(p->to);
}
int main() {
	int ans = 0;
	scanf("%d%d", &N, &K);
	for(int i=1;i<=N;i++) {
		scanf("%d", &fa[i]);
		if( i != 1 ) addedge(fa[i], i);
		else if( fa[i] != 1 ) ans++;
		a[i].ind = i;
	}
	dfs(1);
	sort(a+1, a+N+1);
	for(int i=N;i>=1;i--) {
		if( a[i].dep <= K ) break;
		if( vis[a[i].ind] ) continue;
		int x = a[i].ind;
		for(int j=1;j<K;j++)
			x = fa[x];
		dfs2(x);
		ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 7168
from sys import stdin
import math
import bisect
from collections import defaultdict

def IL():return list(map(int, stdin.readline().split()))
def ItoSList(): return list(map(int,list(stdin.readline())))
def IL_reverse():return list(map(int, stdin.readline().split())).reverse()
def Int_all():return list(map(int, stdin))
def sumIL():return sum(list(map(int, stdin.readline().split())))
def SL():return list(map(int, stdin.readline().split()))
def Str_all():return list(map(int, stdin))
def tDL(p,q):return [[0 for i in range(p)] for j in range(q)]


def floyd_warshall():
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])    

N=10
res = float('inf')
dist = [[float("inf")] * N for i in range(N)]
def main():
	H,W = IL()
	for i in range(N):
		dist[i][i] = 0
	
	G = [[] for i in range(N)]
 
	for i in range(10):
	    l = IL()
	    for j in range(10):
	        dist[i][j] = l[j]
	floyd_warshall()

	ans = 0
	memo={}
	for i in range(H):
	    for i in IL():
	        if abs(i) == 1:
	          pass
	        elif i in memo:
	          ans += memo[i]
	        else:
	            t = dist[i][1] 
	            memo[i] = t
	            ans += t
	print(ans)

if __name__ == "__main__": main()


Measured memory_bytes: 3440
n = int(input())
a = [int(a) for a in input().split()]
flag = [0] * (n + 1)
ret = []
for i in range(n, 0, -1):
    if flag[i] ^ a[i - 1] == 1:
        ret.append(i)
        j = 1
        while j * j <= i:
            if i % j == 0:
                flag[j] ^= 1
                if j * j != i:
                    flag[i // j] ^= 1
            j += 1
print(len(ret))
if len(ret) > 0:
    print(" ".join(map(str, ret)))


Measured memory_bytes: 86888
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
  int a;
  string s;
  cin >> a >> s;

  cout << (a>=3200? s : "red") << endl;
}

Measured memory_bytes: 888