akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())

from collections import Counter
cnt = Counter()
for i in range(H):
    cnt.update(input())

num = [0 for i in range(3)]
for c in cnt.values():
    num[2] += c // 4
    if c % 4 == 1:
        num[0] += 1
    elif c % 4 == 2:
        num[1] += 1
    elif c % 4 == 3:
        num[0] += 1
        num[1] += 1

h2 = H // 2
w2 = W // 2
if H % 2 == 0 and W % 2 == 0:
    numOK = [0, 0, h2 * w2]

elif H % 2 != 0 and W % 2 != 0:
    numOK = [1, h2 + w2, h2 * w2]

else:
    if H % 2 == 0: e2 = h2
    else: e2 = w2
    numOK = [0, e2, h2 * w2]

num[2] -= numOK[2]
if num[2] < 0:
    print('No')
else:
    num[1] += num[2] * 2
    if num[1] == numOK[1] and num[0] == numOK[0]:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3316
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int[][][] dorm = new int[4][3][10];
        
        int n = in.nextInt();

        //input
        for(int i = 0; i < n; i++){
            int bill = Integer.parseInt(in.next()), floor = Integer.parseInt(in.next()),
                room = Integer.parseInt(in.next()), value = Integer.parseInt(in.next());
            
            dorm[bill-1][floor-1][room-1] += value;
        }

        PrintWriter out = new PrintWriter(System.out);
        //output
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 10; k++){
                    out.printf(" %d", dorm[i][j][k]);
                }
                out.println();
            }
            if(i < 3){
                for(int j = 0; j < 20; j++)out.print('#');
                out.println();
            }
        }
        out.flush();
    }
}


Measured memory_bytes: 30020
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)

N, M, P = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

to = [[] for _ in range(N + 1)]
ot = [[] for _ in range(N + 1)]
edges = [[] for _ in range(N + 1)]

for a, b, c in X:
    edges[a].append((b, c - P))
    to[a].append(b)
    ot[b].append(a)

ok_1 = [False] * (N + 1)
ok_n = [False] * (N + 1)
ok_1[1] = True
ok_n[N] = True

q = deque()
q.append(1)
while q:
    u = q.popleft()
    for v in to[u]:
        if not ok_1[v]:
            ok_1[v] = True
            q.append(v)
            
q = deque()
q.append(N)
while q:
    u = q.popleft()
    for v in ot[u]:
        if not ok_n[v]:
            ok_n[v] = True
            q.append(v)

INF = 10 ** 9 + 7
d = [INF] * (N + 1)
d[1] = 0
updated = True
cnt = 0
while updated and cnt <= N:
    updated = False
    cnt += 1
    for u in range(1, N + 1):
        if not ok_1[u] or not ok_n[u]:
            continue
            
        for v, c in edges[u]:
            if not ok_1[v] or not ok_n[v]:
                continue
                
            if d[v] > d[u] - c:
                d[v] = d[u] - c
                updated = True

if cnt > N:
    print(-1)
else:
    print(max(0, -d[-1]))


Measured memory_bytes: 77636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            // 整数配列の入力
            var ary = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var x = ary[0];

            var ps = Console.ReadLine().Split(' ').Where( i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();

            long larger = 0;
            for (var i = x; i < 102; i++)
            {
                if(!ps.Contains(i))
                {
                    larger = i;
                    break;
                }
            }

            for(var i = x - 1; i >= -1; i--)
            {
                if (!ps.Contains(i))
                {
                    if( larger - x < x - i)
                    {
                        Console.WriteLine(larger);
                    }
                    else
                    {
                        Console.WriteLine(i);
                    }
                    break ;
                }
            }


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28392
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
a.sort()

def combination(n, r): #nCrを求める
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp
# print (a)

j = bisect_left(a, a[-1]//2)
# print (j)
tmp = abs(a[j]/a[-1] - 1/2)
ans1 = a[-1]
ans2 = a[j]
if j != 0:
    if tmp >= abs(a[j - 1]/a[-1] - 1/2):
        ans2 = a[j - 1]

print (ans1, ans2)    

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  map<int, int> m;
  for (int i = 0; i < N; i++) m[a[i]]++;
  int ans = 0;
  for (auto i : m) {
    if (i.first > i.second) ans += i.second;
    else if (i.first < i.second) ans += i.second - i.first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <string>

using namespace std;


class Linked_list{
  struct Item{
    int num;
    Item* next;
    Item* prev;
  };
  Item *first,*last;

  public:
  Linked_list(){
    first = NULL;
    last = NULL;
  }

  void insert(int x){
    Item* item = new Item();
    item->num = x;
    item->prev = NULL;
    item->next = first;
    if(item->next!=NULL) item->next->prev = item;
    first = item;
    if(last == NULL) last = item;
  }

  void delete_item(int x){
    Item* item = first;
    while(item != NULL){
      if(item->num == x){
        if(item->prev!=NULL){ item->prev->next = item->next;
         } else { first = item->next; }
        if(item->next!=NULL){ item->next->prev = item->prev;
        } else { last = item->prev; }
        delete item;

        return;
      }
      item = item->next;
    }
  }

  void delete_first(){
    Item *item = first;
    if(first->next == NULL) last = NULL;
    first = item->next;
    delete item;
    if(first!=NULL)first->prev = NULL;
  }

  void delete_last(){
    Item *item = last;
    if(last->prev == NULL) first = NULL;
    last = item->prev;
    if(last!=NULL) last->next = NULL;
    delete item;
  }

  int pop_first(){
    Item *item = first;
    first = item->next;
    return item->num;
  }

  bool is_empty(){
    return first == NULL;
  }
};

int main(){
  ios::sync_with_stdio(false);
  Linked_list list;
  int n;
  string ope;
  cin>>n;
  for(int i=0;i<n;i++){ 
    cin>>ope;
    if(ope=="insert"){
      int x;
      cin>>x;
      list.insert(x);
    }else if(ope=="delete"){
      int x;
      cin>>x;
      list.delete_item(x);
    }else if(ope=="deleteFirst"){
      list.delete_first();
    }else if(ope=="deleteLast"){
      list.delete_last();
    }
  }

  int count = 0;
  while(!list.is_empty()){
    if(count)cout<<" ";
    cout<<list.pop_first();
    count++;
  }
  cout<<endl;
}

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

using namespace std;

vector< int > g[100000];
int dist[100000], ans[100000];

void dfs1(int idx, int par)
{
  for(int &to : g[idx]) {
    if(to == par) continue;
    dfs1(to, idx);
    dist[idx] = max(dist[idx], dist[to] + 1);
  }
}

void dfs2(int idx, int d_par, int par)
{
  vector< pair< int, int > > d_child;
  d_child.emplace_back(0, -1);
  for(int &to : g[idx]) {
    if(to == par) d_child.emplace_back(d_par + 1, to);
    else d_child.emplace_back(dist[to] + 1, to);
  }
  sort(d_child.rbegin(), d_child.rend());
  ans[idx] = d_child[0].first;
  for(int &to : g[idx]) {
    if(to == par) continue;
    dfs2(to, d_child[d_child[0].second == to].first, idx);
  }
}

int main()
{
  int N;
  cin >> 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);
  }

  dfs1(0, -1);
  dfs2(0, 0, -1);
  for(int i = 0; i < N; i++) {
    cout << (N - 1) * 2 - ans[i] << endl;
  }
}


Measured memory_bytes: 28072
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

int main(){
    int n,k;cin>>n>>k;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    rep(i,0,k){
        vector<int> base(n,0);
        rep(j,0,n){
            base[max(j-a[j],0)]++;
            if (j+a[j]+1<n){
                base[j+a[j]+1]--;
            }
        }
        vector<int> b(n,0);
        b[0] = base[0];
        rep(i,1,n){
            b[i]=b[i-1]+base[i];
        }
        if (a==b) break;
        a = b;
    }
    rep(i,0,n){
        cout<<a[i]<<" ";
    }
    putchar('\n');
}

Measured memory_bytes: 5652
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = Array.of_list @@ [0] @ (read_line () |> split_string ~pattern:" " |> List.map int_of_string) @ [0]

let prices = Array.init (n + 1) (fun i -> abs (a.(i) - a.(i + 1)))
let sum = Array.fold_left (+) 0 prices

let () =
  for i = 1 to n do
    Printf.printf "%d\n" @@ sum - prices.(i - 1) - prices.(i) + abs (a.(i - 1) - a.(i + 1))
  done

Measured memory_bytes: 22920
// AOJ ITP 1_6_D
#include<cstdio>
#define rep(i,a) for( int i = 0; i != (a); ++i )

int a[100][100], b[100];

int main()
{
	int n, m;
	scanf( "%d%d", &n, &m );
	rep( i, n )
		rep( j, m )
			scanf( "%d", &a[i][j] );

	rep( i, m )
		scanf( "%d", b+i );

	rep( i, n )
	{
		int c = 0;
		rep( j, m )
			c += a[i][j]*b[j];
		printf( "%d\n", c );
	}

	return 0;
}

Measured memory_bytes: 1068
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

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


def main():
    n = int(input())
    print(n ** 3)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

int main() {
  int a , b ;
  string op ;
  
  cin >> a >> op >> b ;
  
  if (op == "+"){
    cout << a + b << endl;
  }
  
if (op == "-"){
    cout << a - b << endl;
}

}
  


Measured memory_bytes: 256
#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 ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N;
int A[100010];

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


signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int ans=A[0];
	REP(i,N){
		ans=gcd(A[i+1],ans);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=500005;
int n,K,tot,js;
int tr[N<<2],a[N],h[N],ne[N<<1],to[N<<1],du[N],ans[N];
priority_queue<int,vector<int>,greater<int> >q;
int query(int l,int r,int s,int t,int i) {
	if(l<=s&&t<=r) return tr[i];
	int mid=(s+t)>>1,re=0;
	if(l<=mid) re=query(l,r,s,mid,i<<1);
	if(mid+1<=r) re=max(re,query(l,r,mid+1,t,(i<<1)|1));
	return re;
}
void chan(int x,int s,int t,int i,int num) {
	if(s==t) {tr[i]=num;return;}
	int mid=(s+t)>>1;
	if(x<=mid) chan(x,s,mid,i<<1,num);
	else chan(x,mid+1,t,(i<<1)|1,num);
	tr[i]=max(tr[i<<1],tr[(i<<1)|1]);
}
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot,++du[y];}
void topsort() {
	for(RI i=1;i<=n;++i) if(!du[i]) q.push(i);
	while(!q.empty()) {
		int x=q.top();q.pop(),ans[x]=++js;
		for(RI i=h[x];i;i=ne[i]) {
			--du[to[i]];
			if(!du[to[i]]) q.push(to[i]);
		}
	}
}
int main()
{
	n=read(),K=read();
	for(RI i=1;i<=n;++i) a[read()]=i;
	for(RI i=1;i<=n;++i) {
		int k=query(max(1,a[i]-K+1),a[i],1,n,1);
		if(k) add(a[k],a[i]);
		k=query(a[i],min(n,a[i]+K-1),1,n,1);
		if(k) add(a[k],a[i]);
		chan(a[i],1,n,1,i);
	}
	topsort();
	for(RI i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 24820
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i< (n);i++)
#define rep1(i,n) for(ll i=1;i<= (n);i++)
using namespace std;
typedef long long ll;
const static ll MOD = (1e+9)+7;

int main(){
    ll n,k;cin>>n>>k;
    ll ans = 0;
    if(n > k){
        ans = n % k;
        if(ans > k/2){
            ans = abs(ans-k);
        }
    }else{
        ans = n;
    }
    if(ans > k/2){
        ans = abs(ans-k);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 1; i <= 9; i++)
            {
                for(int j = 1; j <= 9; j++)
                {
                    Console.WriteLine(i + "x" + j + "=" + i * j);
                }
            }
        }
    }
}

Measured memory_bytes: 8860
N, M = gets.split.map(&:to_i)

class Node
  attr_accessor :parent, :rank

  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFindTree
  def initialize(n)
    @nodes = (0..n).to_a.map { |i| Node.new(i) }
  end

  def find(x)
    return x if @nodes[x].parent == x

    return @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b

    if @nodes[a].rank < @nodes[b].rank
      @nodes[a].parent = b
    else
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end

  def parents
    @nodes.map(&:parent)
  end

  def nodes
    @nodes
  end
end

tree = UnionFindTree.new(N - 1)

M.times do
  d = gets.split.map(&:to_i)
  tree.unite(d[0] - 1, d[1] - 1)
end

N.times do |i|
  tree.find(i)
end

p tree.parents.uniq.size

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

int main() {
	string s,t;cin>>s>>t;
	int flag=0;
	for(int i=0;i<s.size();i++){
		string s2=s;
		for(int j=1;j<s.size();j++){
			s2[j]=s[j-1];
		}
		s2[0]=s[s.size()-1];
		s=s2;
//		cout<<s<<endl;
		if(s==t)flag=1;
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define ll long long int
using namespace std;

int main(int argc, char const* argv[])
{
		int a, b;
		cin >> a >> b;
		int x = (a <= b) ? 1 : 0;
		cout << a - 1 + x << endl;
	return 0;
}


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

int main()
{
  uint64_t N,K;
  std::cin>>N>>K;
  
  std::vector<uint64_t> A(N);
  for(auto &e:A)
    std::cin>>e;
  
  std::vector<uint64_t> flag(N, 0);
  uint64_t loopCount=0;
  uint64_t loopStartCount=0;
  uint64_t loopStartPos=0;
  uint64_t currentPos=1;
  for(uint64_t i=1;;i++)
  {
    if(i==K)
    {
      int64_t result=A[currentPos-1];  
      std::cout<<result<<std::endl;
      return 0;
    }
    currentPos=A[currentPos-1];
    if(flag[currentPos-1]!=0)
    {
      loopCount=i-flag[currentPos-1];
      loopStartCount=flag[currentPos-1];
      loopStartPos=currentPos;
      break;
    }
    flag[currentPos-1]=i;
  }
  
  uint64_t newK=(K-loopStartCount)%loopCount;
  currentPos=loopStartPos;
  for(uint64_t i=0;i!=newK;i++)
  {
    currentPos=A[currentPos-1];
  }
  
  int64_t result=currentPos;
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 6076
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  int n,k;cin>>n>>k;
  vi h(n);
  rep(i,n)cin>>h[i];
  sort(h.begin(),h.end());
  int ans=INF;
  for(int i=0;i+k-1<n;i++){
    ans=min(ans,h[k-1+i]-h[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int main()
{
  int a ,b, c, d, e, X, Y;
  //long long  a, b, c, d, e, X, Y;
  //  double  c;
  int  A[200003]={};
//  long long  A[100003]={};
//  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
  char tmp[101]={};
  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  long long ans=1;
  int max=0;
  int addr=0;
  int ptn=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
//  scanf("%d%d", &a,&c);
//  cnt = strlen(t);
// printf("%d\n",a);
  scanf("%d", &X);
  for(i=0;i<X;i++){
    scanf("%d", &A[i]);
  }
//  for(i=0;i<X;i++){
//    printf("%d ", A[i]);
//  }
//puts("");
  qsort(A, X, sizeof(int), compare_int);
//  for(i=0;i<X;i++){
//    printf("%d ", A[i]);
//  }
  

  printf("%d\n",A[X/2]-A[X/2-1]);
  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   
//  ans=a*3;
//  ans=(ans+b)/2;
//  printf("%d\n", ans);

  
//  printf("%lf\n",ans);
  //  //  if(flag==0)   printf("TLE\n");
//    if(max < cnt - max)  printf("Yes\n");
//    else  printf("No\n");
  
return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main(){
  int h,w;
  while(true){
    cin >> h >> w;
    if(h==0&&w==0) break;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
	if(i == 0 || i == h-1 || j == 0 || j == w-1){
	  cout << "#";
	}else{
	  cout << ".";
	}
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
  N = W*H
  |E| = N-1
*/

int main()
{
  int w, h;
  cin >> w >> h;

  vi p(w), q(h);
  rep(i, w) cin >> p[i];
  rep(j, h) cin >> q[j];

  priority_queue<pii, vector<pii>, greater<pii>> que;  
  rep(i, w) que.push(mp(p[i], 0));
  rep(j, h) que.push(mp(q[j], 1));

  w++; h++;
  ll ans = 0;
  while(!que.empty()){
    pii a = que.top();
    que.pop();

    if(a.second == 0){
      ans += (ll)h*a.first;
      w--;
    }else{
      ans += (ll)w*a.first;
      h--;
    }
//    cout << a.first << "," << a.second << " : " << ans << endl;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3316
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int x=sc.nextInt();
    int y=sc.nextInt();
    int sum1=0;
    for(int i=1;i<=n;i++) {
      if(i<=k) {
        sum1=sum1+x;
      } else {
        sum1=sum1+y;
      }
    }
    System.out.println(sum1);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	string s;
	cin >> s;

	int q;
	cin >> q;

	vector<char>front;
	vector<char>back;

	int cnt = 0;

	int prev = 0;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;

		

		if (t == 1) {//反転
			cnt++;
		}
		else {
			int f;
			cin >> f;
			char c;
			cin >> c;
			if (f == 1) {//前方
				if (cnt%2==1) {
					back.push_back(c);
				}
				else {
					front.push_back(c);
				}

			}
			else {//後方
				if (cnt % 2 == 1) {
					front.push_back(c);
				}
				else {
					back.push_back(c);
				}
			}

		}

	}

	if (cnt % 2 == 1) {
		
		//reverse(front.begin(), front.end());
		reverse(back.begin(), back.end());
		for (int i = 0; i < back.size(); i++) {
			cout << back[i];
		}
		
		for (int i = s.size()-1; i >=0; i--) {
			cout << s[i];
		}

		for (int i = 0; i < front.size(); i++) {
			cout << front[i];
		}


	}
	else {
		for (int i = front.size()-1; i >=0; i--) {
			cout << front[i];
		}
		cout << s;
		for (int i = 0; i < back.size(); i++) {
			cout << back[i];
		}
	}



	return 0;

}

Measured memory_bytes: 1024
n,m = gets.split(" ").map(&:to_i)
list = gets.split(" ").map(&:to_i)

sum = 0

for value in 0...list.length do
  sum = sum + list[value]
end

pre = sum / (4.0 * m)

ans = list.select { |num| num >= pre }

if ans.length >= m  then
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



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

	vector<int> p(n,0);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 1; i < n-1; i++) {

		if (p[i - 1] < p[i] && p[i] < p[i + 1]) {
			ans++;
		}
		else if (p[i - 1] > p[i] && p[i] > p[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;





	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	x := scanInt()

	var mon int
	var ans int
	mon = 100

	for {
		if x <= mon {
			break
		}
		mon += mon / 100
		ans++
	}

	fmt.Println(ans)
}

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

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

int main() {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double deg_h = 2 * M_PI * (H*60 + M) / 720.0;
  double deg_m = 2 * M_PI * M / 60.0;
  double ans = sqrt(A*A + B*B - 2*A*B*cos(deg_h - deg_m));
  printf("%.10lf\n", ans);
}

Measured memory_bytes: 4212
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	input = input.map(e => toInt(e));
	var n = input[0];
	var ans = 0;
	var M = 0;
	var x = 0;
	for(var i = 1; i <= n; i++){
		x = input[i];
		ans += x;
		M = max(M,x);
	}
	ans -= M/2;
	ans = toInt(ans);
	console.log(ans);
}

Measured memory_bytes: 21064
def dec(n):
    return n % 10 != 0

n = int(input())
s = [int(input()) for _ in range(n)]
s.sort()

if dec(sum(s)):
    print(sum(s))
else:
    for i in s:
        if dec(i):
            print(sum(s) - i)
            break
    else:
        print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <queue>
using namespace std;

int main () {
	int n, size;
	string cmd, str;
	set<string> dic;
	queue<string> yn;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> cmd >> str;
		if(cmd == "insert")
			dic.insert(str);
		else {
			if (dic.count(str))
				yn.push("yes");
			else
				yn.push("no");
		}
	}
	size = yn.size();
	for(int i = 0; i < size; i++) {
		cout << yn.front() << endl;
		yn.pop();
	}	
	return 0;
}

Measured memory_bytes: 56140
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

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

    int ans = A + B;
    ans = max(ans, A - B);
    ans = max(ans, A * B);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define fs first
    #define sc second
    #define int long long

    using namespace std;

    bool a[30 * 1000 + 1];
    signed main() {
        for (int i = 2; i <= 30 * 1000; i += 2) {
            a[i] = true;
        }
        for (int i = 3; i <= 30 * 1000; i += 3) {
            a[i] = true;
        }

        int n;
        cin >> n;
        int sum = 0;
        for (int i = 2; i <= 30 * 1000; i++) {
            if (a[i]) {
                cout << i << ' ';
                n--;
                sum += i;
                if (n == 1) {
                    for (int j = 2; ; j++) {
                        if ((!a[j] || j > i) && (sum + j) % 6 == 0 && __gcd(sum, j) != 1) {
                            cout << j;
                            return 0;
                        }
                    }
                }
            }
        }
        return 0;
    }


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

 vector<int> d(n);
 rep(i,n) {
     cin >> d[i];

 }
 int result = 1000000;
 
 
 for(int p = 1; p < 100; p++){
     int ans =0;
    rep(i,n) {
        ans += (d[i] - p)*(d[i] - p);
    }
    result = min(result, ans);
 }
 
 cout << result <<endl;

 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    if (k <= b)
    {
        if (a == b && a % k == 0)
            cout << "OK";
        else if (a % k == 0 || b % k == 0)
            cout << "OK";
        else
        {
            if (a % k == 0)
            {
                if (a + k <= b)
                    cout << "OK";
                else
                    cout << "NG";
            }
            else
            {
                if (a + (k - a % k) <= b)
                    cout << "OK";
                else
                    cout << "NG";
            }
        }
    }
    else
        cout << "NG";
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;

int main(){
	int n;
	while(cin >> n && n){
		n = n + 1;
		vector<int> v(n);
		for(int i = 0 ; i < n ; i++){
			cin >> v[i];
		}
		int ans = 0;
		for(int i = 0 ; i < n ; i++){
			vector<int> nw;
			for(int j = 0 ; j < n ; j++){
				if( i != j ) nw.push_back(v[j]);
			}
			long long d = nw[1] - nw[0];
			int bad = 0;
			for(int j = 0 ; j < nw.size() ; j++){
				if( nw[j] != nw[0] + j * d ){
					bad = 1;
				}
			}
			if( bad == 0 ){
				ans = max(v[i],ans);
			}
		}
		cout << ans << endl;
	}
}

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

const int INF = (1LL << 31) - 1;
const int MAX_N = 1 << 17;
int n,dat[2* MAX_N -1];

void init(int n_){
  //簡単のため要素数を２のべき乗に
  n = 1;
  while(n < n_) n *= 2;
  fill(dat,dat+2*n-1,INF);
}

void update(int k, int a){
  k += n-1;
  dat[k] = a;
  while(k > 0){
    k = (k-1)/2;
    dat[k] = min(dat[2*k+1],dat[2*k+2]);
  }
}

int query(int a,int b,int k,int l,int r){
  if(r <= a || b <= l) return INF;
  if(a <= l && r <= b) return dat[k];
  else {
    int vl = query(a,b,2*k+1,l,(l+r)/2);
    int vr = query(a,b,2*k+2,(l+r)/2,r);
    return min(vl,vr);
  }
}

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

  int q; cin >> n >> q;
  init(n);
  for(int i = 0; i < q; i++){
    int com,x,y; cin >> com >> x >> y;
    if(com) cout << query(x,y+1,0,0,n) << endl;
    else update(x,y);
  }

  return 0;
}



Measured memory_bytes: 5196
S = [list(map(int, i.split())) for i in input()]

num = []
for i in range(len(S)-2):
    aa = []
    aa.append(S[i])
    aa.append(S[i+1])
    aa.append(S[i+2])
    aa = sum(aa, [])
    aa = "".join(list(map(str, aa)))
    test = abs(int(aa) - 753)
    num.append(test)

minimum = min(num)
print(minimum)

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

int main() {
    string s;
    cin >> s;
    int ans=0;
    if(s.size()==1) ans=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	int n, k;
	cin >> n >> k;
	ll z = n / k;
	ans = z * z * z;
	if(k % 2 == 0){
		ll h = (n+k/2)/k;
		ans += h*h*h;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
blue = [input() for _ in range(n)]
m = int(input())
red = [input() for _ in range(m)]

ans = 0

def count_br(moji, s, t):
  count = 0
  for i in s:
    if i == moji:
      count += 1
  for i in t:
    if i == moji:
      count -= 1
  return count

for i in range(len(blue)):
  ans = max(ans, count_br(blue[i], blue, red))
  
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const ll maxn=1e9+7;
ll h[100005];
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    for(int i=0;i<n;i++) cin>>h[i];
    ll l=-1,r=maxn;
    while(r-l>0){
        ll mid=(l+r)/2;
        ll ans=0;
        for(int i=0;i<n;i++){
            if(mid*b<h[i]) ans+=ceil((double)(h[i]-mid*b)/(a-b));
        }
        if(ans<=mid) r=mid;
        else{
            if(r-l==1) l=mid+1;
            else l=mid;
        }
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	int n, ans = 0, primes[95] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499 };
	cin >> n;
	while (n){
		for (int i = n + 1; i <= n << 1; i++){
			for (int w = 0; i >= primes[w]*primes[w]; w++){
				if (!(i%primes[w])){
					ans--;
					break;
				}
			}
			ans++;
		}
		cout << ans << endl;
		ans = 0;
		cin >> n;
	}
	return 0;
}

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

int main() {
  int n;cin>>n;
  vector<int> s(n);
  rep(i,n) cin>>s[i];
  int max=0,counter=0;
  rep(i,n) {
    if (s[i]>=max) {
      max=s[i];
      counter++;
    }
  }
  cout<<counter<<endl;
}

Measured memory_bytes: 256
//
// ~oisín~ C++ Template
//

#include                <bits/stdc++.h>
#define MX_N            5001
#define mp              make_pair
#define mod7            1000000007
#define modpi           314159
#define PI              3.141592653589793238
#define pb              push_back
#define FastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define All(a)          a.begin(),a.end()
#define fi              first
#define se              second
#define ll              long long int
#define ull             unsigned long long int

int kx[8]  =            {+2, +2, -2, -2, +1, +1, -1, -1};
int ky[8]  =            {+1, -1, +1, -1, +2, -2, +2, -2};
int d9x[9] =            {+1, +1, +1, +0, +0, +0, -1, -1, -1};
int d9y[9] =            {+1, +0, -1, +1, +0, -1, +1, +0, -1};
int dx4[4] =            {+0, +0, +1, -1};
int dy4[4] =            {+1, -1, +0, +0};

ll gcd(ull a, ull b){
    return (a==0)?b:gcd(b%a,a);
}

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

const long long INF = 1e18;

using namespace std;

int main(){
    int L, R;
    cin >> L >> R;
    int d;
    cin >> d;
    int ans = 0;
    for(int i=L;i<=R;++i){
        ans += (i % d == 0);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
  int i,n;
  for(i=1; i<10; i++){

    printf("1x%d=%d\n" ,i,1*i);
  }
 for(i=1; i<10; i++){

    printf("2x%d=%d\n" ,i,2*i);
  
}

 for(i=1; i<10; i++){

    printf("3x%d=%d\n" ,i,3*i);
 }
for(i=1; i<10; i++){

    printf("4x%d=%d\n" ,i,4*i);
 }
for(i=1; i<10; i++){

    printf("5x%d=%d\n" ,i,5*i);
 }
for(i=1; i<10; i++){

    printf("6x%d=%d\n" ,i,6*i);
 }
for(i=1; i<10; i++){

    printf("7x%d=%d\n" ,i,7*i);
 }

for(i=1; i<10; i++){

    printf("8x%d=%d\n" ,i,8*i);
 }
for(i=1; i<10; i++){

    printf("9x%d=%d\n" ,i,9*i);
 }



 return 0;
}

Measured memory_bytes: 520
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 3000;
ld dp[MAXN][MAXN];
ld a[MAXN];
ll n;

ld rec(ll head,ll tail){
    if(head + tail == n){
        if(head > tail) return 1.00;
        else return 0.00;
    }

    ld &ans = dp[head][tail];

    if(ans >= 0) return ans;

    ans = 0.00;
    ans = ans + rec(head+1,tail)*a[head+tail+1];
    ans = ans + rec(head,tail+1)*(1.00 - a[head+tail+1]);

    return ans;
}

void solve(){
    cin>>n;

    for(ll i=0;i<MAXN;i++) for(ll j=0;j<MAXN;j++) dp[i][j] = -1.00;
    FOR(i,1,n) cin>>a[i];

    ld ans = rec(0,0);
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

signed main(){


    FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    while(t--) solve();
    
}

Measured memory_bytes: 141184
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  c[n - 1] = 0;
  rep (i, n) cin >> a[i];
  rep (i, n) cin >> b[i];
  rep (i, n - 1) cin >> c[i];

  rep (i, n) {
    a[i]--;
  }

  int ans = b[a[0]];
  for (int i = 1; i < n; i++) {
    ans += b[a[i]];
    if (a[i - 1] == a[i] - 1) ans += c[a[i - 1]];
  }
  P(ans);

  return 0;
}

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

$list = [["a"]];
if ($n === 1) {
	echo implode($list[0]);
	exit();
}

$result = [];
dfs([0], 1);

$alpha = array_slice(range("a", "z"), 0, $n);
$strings = [];
foreach ($result as $array) {
	$str = array_reduce($array, function($str, $idx) use($alpha){
		return $str .= $alpha[$idx];
	}, "");
	$strings[] = $str;
}
echo implode(PHP_EOL, $strings);

function dfs($idx_array, $max){
	global $n;
	global $result;
	$tmp = $idx_array;
	for ($i=0; $i <= $max; $i++) { 
		array_push($idx_array, $i);
		if (count($idx_array) === $n) {
			$result[] = $idx_array;
		} else {
			$new_max = ($i == $max) ? $max+1 : $max;
			dfs($idx_array, $new_max);
		}
		$idx_array = $tmp;
	}
}

Measured memory_bytes: 100336
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, m = LI()
    a = LI()
    a = sum(a)
    print(-1 if a > n else n - a)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 83872
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
   int K,T;
   cin >> K >> T;
   priority_queue<pair<int,int>> as;
   for( int i =0; i<T; i++){
      int a;
      cin >> a;
      as.push(make_pair(a,i));
   }
   int before=-1;
   int ans=0;
   while( as.size() != 0 ){
      pair<int,int> best = as.top();
      as.pop();
      if( before == best.second ){
         if(as.size()!=0){
            pair<int,int> next = as.top();
            as.pop();
            next.first--;
            as.push(best);
            before=next.second;
            if(next.first >0 ) as.push(next);
         }else{
            ans++;
            best.first--;
            before=best.second;
            if(best.first >0 ) as.push(best);
         }
      }
      else{
         best.first--;
         before=best.second;
         if(best.first >0 ) as.push(best);
      }
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

signed main(){
    int n; cin >> n;
    vector<pair<int,int>> food(n);
    int A[n],B[n];
    REP(i,n){
        int a,b; cin >> a >> b;
        food[i] = {a+b,i};
        A[i] = a;
        B[i] = b;
    }
    sort(rall(food));
    int ans = 0;
    REP(i,n){
        if(i%2 == 0) ans += A[food[i].second];
        else ans -= B[food[i].second];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
m = dict()
a0 = [1,3,5,7,8,10,12]
a1 = [4,6,9,11]
a2 = [2]

for i,j in enumerate([a0,a1,a2]):
    for k in j:
        m[k] = i

a, b = map(int, input().split())

if m[a] == m[b]:
    print("Yes")
else:
    print("No")


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    
    int x,n;
    cin>>x>>n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int> mp;
    for(int i=-10;i<110;i++) mp[i]++;
    rep(i,n){
        mp[a[i]]=0;
    }
    int ans=1000;
    int memo;

    for(auto y:mp){
        if(y.sc!=0){
            if(chmin(ans,abs(y.fs-x))) memo=y.fs;
        }
    }
    cout<<memo<<endl;
    
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7788
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int calc(int money,int year,double rate,int type,int tax){
	//cout << money << " " << year << " " << rate << " " << type << " " << tax << endl;
	if( type == 1 ){
		int ans = 0;
		for(int i = 0 ; i < year ; i++){
			money = money + money * rate - tax;
		}
		return money;
	}else{
		int ans = 0;
		for(int i = 0 ; i < year ; i++){
			ans += money * rate;
			money -= tax;
		}
		return money+ans;
	}
}
int main(){
	int T;
	cin >> T;
	while(T--){
		int money;
		int y,n;
		cin >> money >> y >> n;
		int ans = 0;
		for(int i = 0 ; i < n ; i++){
			int type,tax;
			double rate;
			cin >> type >> rate >> tax;
			ans = max( ans , calc(money,y,rate,type,tax) );
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
using System;

namespace abc173
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var acc = 0;
            var wac = 0;
            var tlec = 0;
            var rec = 0;
            for (var i = 0; i < n; ++i)
            {
                switch (Console.ReadLine())
                {
                    case "AC":
                        ++acc;
                        break;
                    case "WA":
                        ++wac;
                        break;
                    case "TLE":
                        ++tlec;
                        break;
                    case "RE":
                        ++rec;
                        break;
                }
            }
            Console.WriteLine("AC x " + acc);
            Console.WriteLine("WA x " + wac);
            Console.WriteLine("TLE x " + tlec);
            Console.WriteLine("RE x " + rec);
        }
    }
}


Measured memory_bytes: 30696