akhauriyash/Code-Regression huggingface dataset:
#-(or child-sbcl swank)
(quit
 :unix-status
 (process-exit-code
  (run-program *runtime-pathname*
               '("--control-stack-size" "64MB"
                 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                 "--eval" "(push :child-sbcl *features*)"
                 "--script" #.(namestring *load-pathname*))
               :output t :error t :input t)))

;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun calc (plan)
  (let* ((h (array-dimension plan 0))
         (w (array-dimension plan 1))
         (visited (make-array (list h w) :element-type 'boolean :initial-element nil))
         (whites 0)
         (blacks 0)
         (sum 0))
    (labels ((recurse (y x)
               (if (aref visited y x)
                   nil
                   (progn
                     (setf (aref visited y x) t)
                     (if (zerop (aref plan y x))
                         (incf whites)
                         (incf blacks))
                     (when (and (< 0 y)
                                (not (= (aref plan y x) (aref plan (- y 1) x))))
                       (recurse (- y 1) x))
                     (when (and (< y (- h 1))
                                (not (= (aref plan y x) (aref plan (+ y 1) x))))
                       (recurse (+ y 1) x))
                     (when (and (< 0 x)
                                (not (= (aref plan y x) (aref plan y (- x 1)))))
                       (recurse y (- x 1)))
                     (when (and (< x (- w 1))
                                (not (= (aref plan y x) (aref plan y (+ x 1)))))
                       (recurse y (+ x 1)))))))
      (dotimes (i h)
        (dotimes (j w)
          (setf whites 0 blacks 0)
          (recurse i j)
          (incf sum (* whites blacks))))
      sum)))

(defun main ()
  (let* ((h (read))
         (w (read))
         (plan (make-array (list h w) :element-type 'bit)))
    (dotimes (i h)
      (let ((line (read-line)))
        (dotimes (j w)
          (setf (aref plan i j) (if (char= #\. (aref line j)) 0 1)))))
    (println (calc plan))))

#-swank(main)


Measured memory_bytes: 41912
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
using namespace std;

int main(){
	int n;
	cin >> n;
	int r[n];
	for(int i = 0; i < n; i++)cin >> r[i];
	int i,min = 1e9 + 1,maxdif = -1e9 - 1;
	for(i = 0; i < n - 1; i++){
		if(r[i] < min){
			min = r[i];
			int max = 0;
			for(int j = i + 1; j < n; j++){
				if(r[j] > max){
					max = r[j];
				}
			}
			if(max - min > maxdif){
				maxdif = max - min;
			}
		}
	}
	cout << maxdif << endl;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, ans = 0;
	cin >> n;
	vector<int> arr(n + 1, 0);
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	int key = 1;
	while(1) {
		if(arr[key]) {
			int x = key;
			key = arr[key];
			arr[x] = 0;
			ans++;
			if(key == 2) break;
		} else {
			ans = -1;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

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

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

    int total = 0;
    for (int i = 0; i < n + 1; i++) {
        total += abs(a[i] - a[i+1]);
    }

    for (int i = 0; i < n; i++) {
        int normal_cost = abs(a[i] - a[i+1]) + abs(a[i+1] - a[i+2]);
        int skipped_cost = abs(a[i] - a[i+2]);

        if (normal_cost > skipped_cost) {
            cout << total - abs(normal_cost - skipped_cost) << endl;
        } else {
            cout << total << endl;
        }
    }

    return 0;
}

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

public class Prime
{
    BitArray Sieve;
    // Sieve of Eratosthenes
    public void Init(int max)
    {
        Sieve = new BitArray(max + 1);
        var end = (int)(Math.Sqrt(max) + 0.1);
        Sieve.Set(1, true);
        for (int i = 2; i <= end; i++)
        {
            if (!Sieve.Get(i))
            {
                for (int j = i * 2; j <= max; j += i)
                {
                    Sieve.Set(j, true);
                }
            }
        }
    }

    public bool IsPrime(int n)
    {
        return !Sieve.Get(n);
    }

    public int[] GetPrimes(int n)
    {
        return Enumerable.Range(2, n - 1).Where(i => !Sieve.Get(i)).ToArray();
    }
}

public static class PrimeFactorize
{
    static List<long> Factorize(long n, IEnumerable<int> primes)
    {
        var factor = new List<long>();
        foreach (var p in primes)
        {
            while (n % p == 0)
            {
                factor.Add(p);
                n /= p;
            }
        }
        if (n > 1)
        {
            factor.Add(n);
        }
        return factor;
    }

    static Dictionary<long, int> FactorToDict(IEnumerable<long> factor)
    {
        var dict = new Dictionary<long, int>();

        foreach (var f in factor)
        {
            if (!dict.ContainsKey(f))
            {
                dict[f] = 0;
            }
            dict[f]++;
        }

        return dict;
    }

    // 要素を各個数で表す
    public static Dictionary<long, int> Factorize(long n)
    {
        var prime = new Prime();
        var max = (int)(Math.Sqrt(n) + 1);
        prime.Init(max);
        var primes = prime.GetPrimes(max);
        return FactorToDict(Factorize(n, primes));
    }
}

public class Solution
{
    static int GetDivSum(long n)
    {
        return GetDivSum(n, new HashSet<long>());
    }

    static int GetDivSum(long n, HashSet<long> used)
    {

        for (int i = 1; i <= n / 2; i++)
        {
            var j = n - i;
            if (j == i)
            {
                continue;
            }
            if (!used.Contains(i) && !used.Contains(j))
            {
                used.Add(i);
                used.Add(j);
                return 1 + GetDivSum(j, used);
            }
        }
        return 1;
    }

    public static void Main()
    {
        var N = long.Parse(Console.ReadLine());
        var factors = PrimeFactorize.Factorize(N);
        var count = 0;
        foreach (var f in factors)
        {
            count += GetDivSum(f.Value);
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 29308
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    int cnt=0;
  cin >>n;
    vector<int> v;
  v.push_back(0);
    for(int i=1; i<=n; i++){
    int num=0; 
    cin >>num;
    v.push_back(num);
    }

for(int i=1; i<=n; i++){
if(i%2==1 && v[i]%2==1) cnt++;
}
cout <<cnt  <<" " <<endl;
return 0;
}


Measured memory_bytes: 3624
s = input()

count1=0
count2=0

for i, name in enumerate(s):  
  if i%2==0:
    if name=='0':
      count1+=1
    else:
      count2+=1
  else:
    if name!='0':
      count1+=1
    else:
      count2+=1
print(min(count1, count2))
    

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
 
int dp[2][5005][2]{};//1 here 0 there
int main(){
    for(int x=0;x<2;x++){
	for(int y=0;y<5000;y++){
	    dp[x][y][0]=dp[x][y][1]=1<<29;
	    }
	}
	dp[0][0][0]=dp[0][1][1]=0;
    int a;
    cin>>a;
    for(int b=1;b<a;b++){
	for(int i=0;i<=a/2;i++)dp[b&1][i][0]=dp[b&1][i][1]=1<<29;
	int c;scanf("%d",&c);
	dp[b&1][0][0]=dp[(b+1)&1][0][0];
	for(int d=a/2;d>=1;d--){
              dp[b&1][d][1]=min({dp[(b+1)&1][d-1][1],dp[(b+1)&1][d-1][0]+c});
	      dp[b&1][d][0]=min({dp[(b+1)&1][d][0],dp[(b+1)&1][d][1]+c});
	    }
	}
   cout<<dp[(a+1)&1][a/2][1]<<endl;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>//K-th Substring
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
  string s;
  int k,n;
  set<string> ans;
  cin>>s;
  cin>>k;
  n=s.size();

  for(char c='a';c<='z';c++){
    for(int i=0;i<n;i++){
      if(s[i]==c){
        for(int j=1;j<=min(k,n-i);j++){
          ans.insert(s.substr(i,j));
        }
      }
    }
    if(ans.size()>=k) break;
  }

  auto it=ans.begin();
  for(int i=1;i<k;i++) it++;
  cout<<*it<<endl;
  return 0;
}


Measured memory_bytes: 256
/* Author rumoisen */
    /* created 2018/10/13 */
     
    #include <vector>
    #include <map>
    #include <string>
    #include <cmath>
    #include <iomanip>
    #include <numeric>
    #include<iostream>
    #include <algorithm>
     
    using namespace std;
     
    #define FOR(i, a, b) for (int i = (a); i < (b); i++)
    #define REP(i, n) FOR(i, 0, n)
    #define SORT(c) sort((c).begin(), (c).end())
    #define INF (ll)1e18
    #define MOD (ll)1e9 + 7
    #define pb push_back
     
    void no(){cout<<"No"<<endl;exit(0);}
    void yes(){cout<<"Yes"<<endl;exit(0);}
    void No(){cout<<"NO"<<endl;exit(0);}
    void Yes(){cout<<"YES"<<endl;exit(0);}
     
    typedef long long ll;
    typedef pair<int, int> P;
    typedef vector<int> V;
    typedef map<int, int> M;
     
    using namespace std;
     
    int main()
    {
        int w,a,b;
        cin>>w>>a>>b;
        if(a+w<b) cout<<b-a-w;
        if((a<=b&&b<=a+w)||(a<=b+w&&b+w<=a+w)) cout<<0;
        if(b+w<a) cout<<a-(b+w);
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int alice=0, bob=0, value;
  int tmp, max;
  
  int N; cin >> N; vector<int> vec(N);
  for(int i=0; i<N; i++) cin >> vec.at(i);

  for(int i=0; i<N; i++){
    max=i;
    for(int j=i; j<N; j++){
      if(vec.at(j) > vec.at(max)) max=j;
    }
    tmp=vec.at(i);
    vec.at(i)=vec.at(max);
    vec.at(max)=tmp;
  }

  
  for(int i=0; i<N; i+=2) alice += vec.at(i);
  for(int i=1; i<N; i+=2) bob += vec.at(i);
  
  value= alice-bob;
  cout << value << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define FALSE 0
#define TRUE 1

int isprime(int x);

int main(void){
  int n, x, i, cnt = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if(isprime(x))
      cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}

int isprime(int x){
  int i;
  if (x == 2)
    return TRUE;
  else if (x < 2 || x % 2 == 0)
    return FALSE;

  i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0)
      return FALSE;
    i += 2;
  }
  return TRUE;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define _LIBCPP_DEBUG 0
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;
//g++ -std=c++1z main.cpp
//.\a.exe
///////////////////////////////////////////////////////////
int main(){
    int n;
    cin >> n;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(n==i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
//////////////////////////////////////////////////////////

Measured memory_bytes: 256
N=int(input())
S=input()

answer=0
for i in range(1,N):
  S1=S[:i]
  S2=S[i:]
  
  s1_set=set()
  for c1 in S1:
    s1_set.add(c1)
  s2_set=set()
  for c2 in S2:
    s2_set.add(c2)
    
  cnt=0
  for c1 in s1_set:
    if c1 in s2_set:
      cnt+=1
      
  answer=max(answer,cnt)
  
print(answer)

Measured memory_bytes: 3064
using System;
 
	class notLate
	{
 
		static void Main(string[] args)
		{
			
			string[] input = Console.ReadLine().Split(' ');
			decimal d = decimal.Parse(input[0]);
			decimal t = decimal.Parse(input[1]);
		    decimal s = decimal.Parse(input[2]);
            
            decimal time=d/s;

            if (t>time){
                Console.WriteLine("Yes");
            }
          
           if(t==time){
           Console.WriteLine("Yes");
           }
             
           if(t<time){
                Console.WriteLine("No");

            }

        }
    }

Measured memory_bytes: 27212
N,K=map(int,input().split())
A=list(map(int,input().split()))
m= [0 for i in range(200001) ]
for i in range(N):
  m[A[i]] += 1
m.sort(reverse=True)
ans = 0
for i in range(K,N):
  if ( m[i] == 0 ):  break
  ans += m[i]
print(ans)


Measured memory_bytes: 32084
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int dp[21][1 << 21];
int zet[1 << 21];
int main()
{
	int num, gen;
	scanf("%d%d", &num, &gen);
	for (int i = 0; i < 21; i++)for (int j = 0; j < (1 << 21); j++)dp[i][j] = 0;
	fill(zet, zet + (1 << 21), 0);
	for (int i = 0; i <= num; i++)
	{
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++)dp[0][(1 << i) + j] = s[j] - '0';
	}
	for (int i = 0; i <= num; i++)
	{
		for (int j = i; j <= num; j++)
		{
			for (int k = 0; k < (1 << j); k++)
			{
				int x = dp[i][(1 << j) + k];
				int r1 = -1, r2 = -1;
				for (int l = i; l < j; l++)
				{
					if ((k&(1 << l)) == 0)
					{
						r1 = l;
						break;
					}
				}
				for (int l = i; l < j; l++)
				{
					if ((k&(1 << l)) != 0)
					{
						r2 = l;
						break;
					}
				}
				int s1 = ((k >> r1) << i) + (k&((1 << i) - 1)), s2 = ((k >> r2) << i) + (k&((1 << i) - 1));
				if (r1 != -1)dp[i + 1][(1 << (j - r1 + i)) + s1] += x;
				if (r2 != -1)dp[i + 1][(1 << (j - r2 + i)) + s2] += x;
				zet[(1 << i) + (k&((1 << i) - 1))] += x;
			}
		}
	}
	string ans;
	for (int i = num; i >= 0; i--)
	{
		for (int j = 0; j < (1 << i); j++)
		{
			//printf("%d %d %d\n", i, j, zet[(1 << i) + j]);
			if (zet[(1 << i) + j] >= gen)
			{
				for (int k = 0; k < i; k++)ans.push_back('0' + (((1 << k)&j) != 0));
				reverse(ans.begin(), ans.end());
				goto l01;
			}
		}
	}
l01:;
	cout << ans << endl;
}


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

using usize = size_t;
using u64 = uint64_t;

usize n;
u64 m;
std::vector<std::tuple<usize, usize, u64, u64>> QS;
std::vector<u64> SQ;

u64 dfs();
int main() {
  usize q;
  std::cin >> n >> m >> q;
  QS.resize(q);
  for (usize i = 0; i < q; i++) {
    usize a, b;
    u64 c, d;
    std::cin >> a >> b >> c >> d;
    QS[i] = std::make_tuple(a - 1, b - 1, c, d);
  }
  std::cout << dfs() << '\n';
}

u64 dfs() {
  u64 res = 0;
  if (SQ.size() == n) {
    for (auto q : QS) {
      usize a, b;
      u64 c, d;
      std::tie(a, b, c, d) = q;
      if (SQ[b] - SQ[a] == c) res += d;
    }
  } else {
    u64 last = SQ.empty() ? 1 : SQ[SQ.size() - 1];
    for (u64 x = last; x <= m; x++) {
      SQ.push_back(x);
      res = std::max(res, dfs());
      SQ.pop_back();
    }
  }
  return res;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,q,i,b,c=0,d,k,p,v;
    cin>>a;
    for(i=0;i<a.length();i++)
    {
        cout<<"x";
    }
    return 0;
}

Measured memory_bytes: 3660
N,A,B,C,D = map(int,input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = input()
if C < D or C < B:
    if '##' in S[A:C+1] or '##' in S[B:D+1]:
        print('No')
    else:
        print('Yes')
else:
    if '##' in S[A:C+1]:
        print('No')
    else:
        if '...' not in S[B-1:D+2]:
            print('No')
        else:
            print('Yes')

Measured memory_bytes: 3572
fun main() {
    val alpha = next()[0].toInt()
    if (alpha in (65..90)) {
        println("A")
    } else {
        println("a")
    }
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }


Measured memory_bytes: 34472
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n;

int calc(int now, int a, int b, int c){
    if(now > n) return 0;
    int res = (a > 0 && b > 0 && c > 0);
    res += calc(now * 10 + 3, a + 1, b, c);
    res += calc(now * 10 + 5, a, b + 1, c);
    res += calc(now * 10 + 7, a, b, c + 1);
    return res;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    cout << calc(0, 0, 0, 0) << endl;
}

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

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

bool pairCompare_ll(const Pll& firstElof, const Pll& secondElof)
{
    if(firstElof.first == secondElof.first) return firstElof.second > secondElof.second;
    else return firstElof.first < secondElof.first;
}

int main() {
    ll N,M;
    cin >> N >> M;
    
    vector<Pll> Ps(N);
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >> b;
        Ps[i]=Pll(a,b);
    }
    sort(Ps.begin(),Ps.end());
    priority_queue<ll> que;
    ll ans=0;
    ll ct=0;
    for(int i=1;i<=M;i++){
        while(Ps[ct].first<=i && ct<N){
            que.push(Ps[ct].second);
            ct++;
        }
        if(!que.empty()){
            ll tmp=que.top();
            que.pop();
            ans+=tmp;
        }
    }
    cout << ans << endl;
    



    return 0;
}

Measured memory_bytes: 2936
/**
 *    author:  Saurav Paul 
 *    created: Jun 06 2020 7:46 PM
**/
#include<bits/stdc++.h>
using namespace std;

#define ll 					  long long int
#define boost		          ios_base::sync_with_stdio(0);
#pragma GCC optimize("O3")
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define eb                    emplace_back
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()
#define bug()				  debug() <<

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

///////////////////////
const int INF = 1e9 + 90;
const ll LINF = 1e18 + 90 ;
using pii = pair<int,int >;
using vec = vector<int> ;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int n , k ; cin >> n >> k;

    vector<long long int> v(n+1) ;
    for(int i = 1 ; i <= n ; i++){
        cin >> v[i] ;
    }
    vector<long long int> path ;
    bool rem[n+1] = {} ;

    long long int x = 1, pos = 1 ;
    long long int reoc = -1 ;
    for(int i = 1 ; i <= k ; i++){
        pos = v[x] ;
        if(rem[pos]){
            reoc = pos ;
            break ;
        }
        rem[pos] = true ;
        path.emplace_back(pos) ;
        x = pos ;
    }
    long long int p = -1 ;
    if(reoc != -1){
        for(int i = 0 ; ; i++){
            if(path[i] == reoc){
                p = i ;
                break ;
            }
        }
    }
    if( k < p){
        cout << path[k-1] << endl ;
    }
    else{
        k -= p ;
        long long int pth = path.size() - p ;
        long long int mod = k % pth ;
        if(mod == 0){
            mod = pth ;
        }
        cout << path[p+mod - 1] << endl ;
    }

    bug() dbg(path) dbg(p) dbg(reoc);

    return 0;
}


Measured memory_bytes: 7088
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int gi(){
  char ch=getchar();int x=0,q=0;
  while(ch<'0' || ch>'9') ch=='-'?q=1:0,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
inline ll Max(ll a,ll b){
  return a>b?a:b;
}
inline ll Min(ll a,ll b){
  return a<b?a:b;
}
int main(){
  int h=gi(),w=gi(),ans,m,M;
  if (h%3==0||w%3==0){
    puts("0"); return 0;
  }
  ans=min(h,w);
  m=w/2,M=m+(w&1);
  for (int i=1; i<h; ++i)
    ans=Min(ans,Max(1ll*(h-i)*w,1ll*i*M)-Min(1ll*(h-i)*w,1ll*i*m));
  m=h/2,M=m+(h&1);
  for (int i=1; i<w; ++i)
    ans=Min(ans,Max(1ll*(w-i)*h,1ll*i*M)-Min(1ll*(w-i)*h,1ll*i*m));
  cout<<ans;
  return 0;
}


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

int main(){
    const int64_t mod = 1e9 + 7;
    int64_t n, ans = 1; string s; cin >> n >> s;
    vector<int> cnt(26, 0);
    for (auto i = 0; i < n; i++) cnt[s[i] - 'a']++;
    for (auto i = 0; i < 26; i++) ans = (ans * (cnt[i] + 1)) % mod;
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 3700
#include<stdio.h>
  
static const int N = 1000000;
 
int cnt;
  
int main(){
  int n, i, j, k, key,m=6;
  int A[N+1],G[6]={2500, 150, 40, 13, 4, 1};
 
  scanf("%d", &n);
  
  cnt = 0;
 
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
    
  for(i = 0;i<m;i++){
    if(G[i]<=n){
      k = i;
      break;
    }
  }
  for(i = k; i < m; i++){
    insertionSort(A, n, G[i]);
 
  }
  printf("%d\n",m - k);
 
  for(i = k; i<m; i++){
    if(i!=k)printf(" ");
    printf("%d",G[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
 
  trace(A, n);
 
  return 0;
}

void insertionSort(int A[], int n, int g){
  int i,j,v;
 
  for(i = g; i<n; i++){
    v = A[i];
    j = i-g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j = j-g;
      cnt++;
    }
      A[j+g] = v;
  }
}
 
void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    printf("%d\n", A[i]);
  }
}

Measured memory_bytes: 4508
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int k, n;
long long A[100000];

int check(long long P)
{
    int i = 0;

    for (int j = 0; j < k; ++j)
    {
        long long sum = 0;

        while (sum + A[i] <= P)
        {
            sum += A[i];
            ++i;

            if (i == n) return n;
        }
    }

    return i;
}

int solve()
{
    long long left = 0;
    long long right = 100000 * 10000;
    long long mid;

    while (right - left > 1)
    {
        mid = (left + right) / 2;

        if (check(mid) >= n)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }

    return right;
}

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

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef long long int ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 10000000000000;

int main() {
	int n;
	int ans = 0;
	cin >> n;
	vector<int> p(n);
	rep(i, 0, n)cin >> p[i];
	rep(i, 1, n - 1) {
		int c[3];
		rep(j, 0, 3)c[j] = p[i + j - 1];
		sort(c, c + 3);
		if (p[i] == c[1])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a1=0
t=0
for i in range(n):
    t+=a[i]
    if i%2==0:
        if t<=0:
            a1+=1-t
            t=1
    else:
        if t>=0:
            a1+=1+t
            t=-1
a2=0
t=0
for i in range(n):
    t+=a[i]
    if i%2==1:
        if t<=0:
            a2+=1-t
            t=1
    else:
        if t>=0:
            a2+=1+t
            t=-1
print(min(a1,a2))

Measured memory_bytes: 63216
#include<stdio.h>

int search(int A[],int n,int key){
	int i=0;
	A[n]=key;
	while(A[i]!=key)i++;
	return i !=n;
}

int main(){
	int i,n,A[10000+1],q,key,sum=0;

	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&A[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
		if(search(A,n,key))sum++;
	}
	printf("%d\n",sum);

return 0;
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main()
{
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (a == b)
    {
        cout << "YES" << endl;
        return 0;
    }
    if (w >= v)
    {
        cout << "NO" << endl;
        return 0;
    }
    if ((v - w) * t >= llabs(a - b))
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <tuple>

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  priority_queue<int> as;
  
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    as.push(a);
  }
  
  for (int i = 0; i < m; i++) {
    int a = as.top();
    as.pop();
    as.push(a/2);
  }
  
  long long int total = 0;
  
  while (!as.empty()) {
    total += as.top();
    as.pop();
  }
  
  cout << total << endl;
}

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

class Program {
    static Scanner cin = new Scanner();

    struct p {
        public int x, y;
        public p(int X, int Y) {
            x = X;
            y = Y;
        }
    }

    static void Main(string[] args) {
        int H = cin.Int();
        int W = cin.Int();
        var S = new string[H+2];

        for (int i = 1; i <= H; i++) {
            S[i] = "." + Console.ReadLine() + ".";
        }

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

        long ans = 0;
        var isSearched = new bool[H + 2, W + 2];

        for (int i = 0; i < W+2; i++) {
            isSearched[0, i] = true;
            isSearched[H + 1, i] = true;
        }
        for (int i = 0; i < H+2; i++) {
            isSearched[i, 0] = true;
            isSearched[i, W + 1] = true;
        }

        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (!isSearched[i, j]) {
                    int black = 0, white = 0;
                    Queue<p> que = new Queue<p>();
                    que.Enqueue(new p(j, i));
                    isSearched[i, j] = true;
                    while (que.Count > 0) {
                        p point = que.Dequeue();
                        if (S[point.y][point.x] == '#') black++;
                        else if(S[point.y][point.x] == '.') white++;
                        for (int k = 0; k < 4; k++) {
                            int ni = point.y + dy[k];
                            int nj = point.x + dx[k];
                            if (1 <= ni && ni <= H && 1 <= nj && nj <= W && !isSearched[ni, nj] && S[point.y][point.x] != S[ni][nj]) {
                                    que.Enqueue(new p(nj, ni));
                                    isSearched[ni, nj] = true;
                            }
                        }
                    }
                    ans += (long)black * white;
                }
            }
        }
        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 17700
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;

ll MOD = 1e9 + 7;
ll n, m, k;

ll my_pow(ll a, ll n)
{
	if (n == 1) return a;
	if (n % 2)
	{
		ll res = my_pow(a, n - 1);
		res *= a;
		return res % MOD;
	}

	ll res = my_pow(a, n / 2);
	return res * res % MOD;
}

ll gb(ll a, ll b)
{
	ll ans = 1;
	for (int i = 1; i <= a; i++)
	{
		ans *= i;
		ans %= MOD;
	}

	for (int i = 1; i <= b; i++)
	{
		ans *= my_pow(i, MOD - 2);
		ans %= MOD;
	}

	for (int i = 1; i <= a - b; i++)
	{
		ans *= my_pow(i, MOD - 2);
		ans %= MOD;
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m >> k;

	ll ans = 0;

	ll t = 0;
	for (ll i = 1; i < m; i++)
	{
		t += i * (m - i) % MOD;
		t %= MOD;
	}
	t *= n * n % MOD;
	t %= MOD;

	ans += t;

	t = 0;
	for (ll i = 1; i < n; i++)
	{
		t += i * (n - i) % MOD;
		t %= MOD;
	}
	t *= m * m % MOD;
	t %= MOD;

	ans += t;
	ans %= MOD;

	ll b = gb(n*m-2, k - 2);
	ans *= b;
	ans %= MOD;
	cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
typedef long long ll;
using namespace std;
ll n,k;
ll ans=0;
int main(){
    scanf("%lld%lld",&n,&k);
    ans+=((n/k)*(n/k)*(n/k));
    if(k%2==0){
        if((n%k)<(k/2)){
            ans+=((n/k)*(n/k)*(n/k));
        }else ans+=(((n/k)+1)*((n/k)+1)*((n/k)+1));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

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

    int count = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s.at(i) != t.at(i))
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;

int main()
{

    int n;
    cin>>n;
    double arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    int i=2;
    double res=arr[0]+arr[1];
    res/=2;
    while(i<n)
    {
        
        double sum=arr[i];
        res+=sum;
        res/=2;
        i++;

    }
    cout<<res<<endl;
    return 0;




    
}

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

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = 0;
		try {
			n = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		double v[] = new double [n];
		String str[] = new String [n];
		String line;
		try {
			line = br.readLine();
			str = line.split(" ");
			for (int i = 0; i < n; i++) {
				v[i] = Integer.parseInt(str[i]);
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		Arrays.sort(v);
		
		for(int i = 0; i < n - 1; i++) {
			v[i+1] = (v[i] + v[i+1]) / 2.0;
		}
		
		System.out.println(v[n-1]);
		
	}
}

Measured memory_bytes: 21204
#include <cstdio>
#include <climits>
#include <algorithm>

using namespace std;

int const N_MAX = 50;

int N, K;
long long xs[N_MAX + 1], ys[N_MAX + 1];

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%lld %lld", &xs[i], &ys[i]);
  }

  long long area = LLONG_MAX;
  for (int xi = 0; xi < N; xi++){
    for (int xj = 0; xj < N; xj++) {
      if (xi == xj) continue;

      long long xl = min(xs[xi], xs[xj]);
      long long xr = max(xs[xi], xs[xj]);

      for (int yi = 0; yi < N; yi++) {
        for (int yj = 0; yj < N; yj++) {
          if (yi == yj) continue;

          long long yd = min(ys[yi], ys[yj]);
          long long yu = max(ys[yi], ys[yj]);

          int count = 0;
          for (int i = 0; i < N; i++) {
            int x = xs[i];
            int y = ys[i];

            if ((x >= xl && x <= xr) && (y >= yd && y <= yu)) count++;
          }
          if (count == K) {
            long long new_area = (xr - xl) * (yu - yd);
            if (new_area < area) area = new_area;
          }
        }
      }
    }
  }
  printf("%lld\n", area);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 100002
using namespace std;
long long n,a[N],t[N],x[N],k;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);a[0]=a[n];
	for(int i=1;i<=n;i++){
		if(i%2)x[1]+=a[i];
		else x[1]-=a[i];
	}
	for(int i=2;i<=n;i++)x[i]=2*a[i-1]-x[i-1];
	for(int i=1;i<=n;i++)printf("%lld ",x[i]);
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  double ans = (double)(n/2+n%2)/(double)n;
  printf("%.10f\n",ans); 
  return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n,m;
char s[510][510],t[510][510],a[510][510];


main(){

  cin>>n>>m;
  rep(i,n){
    cin>>a[i];
    rep(j,m){
      s[i][j]=a[i][j];
      t[i][j]=a[i][j];
    }
  }

  rep(i,n){
    rep(j,m-1){
      if(j==0)
        s[i][j]='#';
      if(i%2) continue;
      s[i][j]='#';
    }
  }

  rep(i,n){
    FOR(j,1,m){
      if(j==m-1)
        t[i][j]='#';
      if(i%2==0) continue;
      t[i][j]='#';
    }
  }

  rep(i,n){
    cout<<s[i]<<endl;
  }

  cout<<endl;

  rep(i,n){
    cout<<t[i]<<endl;
  }

}


Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  int x = 0;
  rep(i,n) scanf("%d",&a[i]), x ^= a[i];
  vi b;
  rep(i,n) b.pb(pcnt(a[i]^(a[i]-1)));
  sort(rng(b));
  reverse(rng(b));
  int ans = 0;
  rep(i,n) {
    int s = b[i];
    if (x >= (1<
>1)) {
      ++ans;
      x ^= (1<<s)-1;
    }
  }
  if (x) ans = -1;
  cout<<ans<<endl;
  return 0;
}































Measured memory_bytes: 1276
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか

int main() {
	string s = "abcdefghijklmnopqrstuvwxyz";
	char a;
	cin >> a;
	for (int i = 0; i < s.size(); i++) {
		if (a == s[i]) {
			cout << s[i + 1];
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

vector<vector<int> > to;
vector<int> order;

bool visited[100100];
int dp[100100];

void dfs(int v) {
    if (visited[v]) return;
    visited[v] = true;

    for (auto u: to[v]) dfs(u);
    order.pb(v);
}

int main() {
    int n, m;
    cin >> n >> m;
    to.resize(n);

    rep(i,m) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        to[x].pb(y);
    }
    
    rep(i,n) {
        if (visited[i]) continue;
        dfs(i);
    }
    reverse(all(order));
    rep(i,n) {
        int v = order[i];
        for (auto u: to[v]) {
            dp[u] = max(dp[v]+1,dp[u]);
        }
    }
    int lp = 0;
    rep(i,n) lp = max(lp,dp[i]);

    cout << lp << endl;

    return 0;
}






















Measured memory_bytes: 8824
#include <iostream>

int main()
{
    int a, b, value;
    char op;
    std::cin >> a >> op >> b;
    if (op == '+')
    {
        value = a + b;
    }
    else
    {
        value = a - b;
    }
    std::cout << value << std::endl;
    return 0;
}


Measured memory_bytes: 256
using System;
class Program{
    static void Main(string[] args){
        string oneLine = Console.ReadLine();
        string twoLine = Console.ReadLine();
        char[] oneChar = new char[oneLine.Length];
        char[] twoChar = new char[twoLine.Length];
        for(int i=0;i<oneLine.Length;i++){
            oneChar[i] = oneLine[i];
        }
        for(int i=0;i<twoLine.Length;i++){
            twoChar[i] = twoLine[i];
        }
        string str = "";
        for(int i=0;i<oneChar.Length;i++){
            str += oneChar[i].ToString();
            if(i >= twoChar.Length){continue;}
            str += twoChar[i].ToString();
        }
        Console.WriteLine(str);
    }
}

Measured memory_bytes: 11092
def judge(N,S):
    x = 0
    maxi = 0
    lst = list(S)
    for i in range(N):
        if lst[i]=="I":
            x += 1
        else:
            x -= 1
        if maxi<x:
            maxi = x
    print(maxi)

N = int(input())
S = input()
judge(N,S)

Measured memory_bytes: 3060
#include <stdio.h>

int main (){
	
	int N;
	scanf("%d", &N);
	
	int num1 = N/100;
	int num2 = (N/10) %10;
	int numb3 = N%10;
	
	while (N>0){
		if (num1 == 7){
			puts ("Yes\n");
		}
		else if (num2 == 7){
			puts ("Yes\n");
		}
		else if (numb3 == 7){
			puts ("Yes\n");
		}
		else {
			puts ("No\n");
		}
		break;
	}
	
		

	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int n;
  cin >> n;
  if(n == 1)cout << "Hello World" << endl;
  if(n == 2){
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int partition(int A[],int p,int r);

int main(void){
	int n,i,base;
	int *A;

	scanf("%d",&n);
	A = (int *)malloc(sizeof(int)*n+1);
	for(i=0;i<n;i++)
		scanf("%d",&A[i]);
	base=partition(A,0,n-1);
	for(i=0;i<n;i++){
		if(i) printf(" ");
		if(i==base)
			printf("[%d]",A[i]);
		else
			printf("%d",A[i]);
	}
	printf("\n");
	return 0;
}
int partition(int A[],int p,int r){
	int x=A[r];
	int i=p-1;
	int j,c;
	for(j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			c=A[i];
			A[i]=A[j];
			A[j]=c;
		}
	}
	c=A[i+1];
	A[i+1]=A[r];
	A[r]=c;
	return i+1;
}

Measured memory_bytes: 996
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n,m,a,b,c,d,p,q;
	cin>>n;
	vector<long long>A(4);
	long long ans=0;
	cin>>p>>q;
	A[0]=p+q,A[1]=p-q,A[2]=-p+q, A[3]=-p-q;
	n--;
	vector<long long>B(4);
	while(n--){
		cin>>p>>q;
		B[0]=p+q,B[1]=p-q,B[2]=-p+q, B[3]=-p-q;
		for(int i=0;i<4;i++) ans=max(ans,abs(A[3-i]+B[i]));
		for(int i=0;i<4;i++) A[i]=max(A[i],B[i]);
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();

}

Measured memory_bytes: 3608
N,M=map(int,input().split())
a=input().split()
A=[]
for _ in a:
    A.append(int(_))
# print(N,M)
# print(A)

# N,M=4, 1
# A=[5, 4, 2, 1]

items=0
votes=sum(A)

for i in range(len(A)):
    if 4*M*A[i]>=votes:
        items+=1
    else:
        pass
if items>=M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9132