akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using point = complex<double>;

const double pi = acos(-1);

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed; cout.precision(10);

    int n;
    cin >> n;
    vector<point> pt(n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        pt[i] = point(x, y);
    }
    vector<double> ans(n);
    for (int i = 0; i < n; ++i) {
        double left = -4 * pi;
        double right = 4 * pi;
        for (int j = 0; j < n; ++j) {
            if (j == i) continue;
            double angle = arg(pt[j] - pt[i]);
            double l = angle;
            double r = angle + pi;
            left = max(left, l);
            right = min(right, r);
        }
        ans[i] = min(2 * pi, max(0.0, right - left));
    }
    for (int i = 0; i < n; ++i) {
        double left = -4 * pi;
        double right = 4 * pi;
        for (int j = 0; j < n; ++j) {
            if (j == i) continue;
            double angle = arg(pt[i] - pt[j]);
            double l = angle;
            double r = angle + pi;
            left = max(left, l);
            right = min(right, r);
        }
        ans[i] = max(ans[i], min(2 * pi, max(0.0, right - left)));
        cout << ans[i] / (2 * pi) << '\n';
    }
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool done[100100],danger[100100];
ll memo[100100];

ll solve(int p){
	if(p<0){
		return 0ll;
	}
	if(done[p]){
		return memo[p];
	}
	done[p] = true;
	if(danger[p]){
		return memo[p] = 0ll;
	}
	if(!p){
		return memo[p] = 1ll;
	}
	return memo[p] = (solve(p-1)+solve(p-2))%MOD;
}

int main(void){
	int n,m,a,i;
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> a;
		danger[a] = true;
	}
	cout << solve(n) << endl;
	return 0;
}


Measured memory_bytes: 4224
def main():
    s = input()
    k = int(input())
    substr = []
    for l in range(len(s)):
        for r in range(l+1,len(s)+1):
            if r-l > k:
                break
            substr.append(s[l:r])
    c=sorted(set(substr))

    print(c[k-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin >> k;
    int sum = 0,cnt = 0;
    while(1){
        sum = (sum * 10 + 7);
        cnt ++;
        sum %= k;
        if(sum  == 0){
            cout << cnt << endl;
            break;
        }
        if(cnt > k){
            cout << -1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <bits/stdc++.h>
#include <set>
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define vii vector<pair<int, int> >
#define si stack<int>
#define pb push_back
#define mp make_pair
#define ALL(T) (T).begin(), (T).end()
#define MODU 1000000007
typedef long long ll;
using namespace std;

ll intmax = (1LL<<32)-1;
ll llmax = (1LL<<60)-1;

const int INF = 1e9 + 5;

class fastio{
public:
	fastio(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	}
} __fastio;

template <typename T>
T abs(T x){
	if(x<0)	return -x;
	else return x;
}

void DFSVisit(int u, vector<int> g[], vector<bool> &visited){ 
    visited[u] = true;
    for(int i=0; i<g[u].size(); i++){
        if(!visited[g[u][i]]){
            DFSVisit(g[u][i], g, visited); 
        }
    }
} 
  
void DFS(vector<int> adj[], int V){
    vector<bool> visited(V, false); 
    for(int u=0; u<V; u++) 
        if(!visited[u]) 
            DFSVisit(u, adj, visited);
}


void solve(){
	
}

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i=0; i<n; i++){
		cin >> h[i];
	}
	for(int i=1; i<n; i++){
		if(h[i] < h[i-1]){
			cout << "No";
			return 0;
		}
		if(h[i] == h[i-1]){
			// do nothing
		}
		else{
			h[i]--;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll minn = inf;
ll N, M, X;
vll C;
vvll A;

void update_minn(ll num) {
    ll sum = 0;
    vll ability(M, 0);
    rep(i, N) {
        if ((num >> i) & 1) {
            sum += C[i];
            rep(j, M) ability[j] += A[i][j];
        }
    }

    rep(i, M) {
        if (ability[i] < X) return;
    }
    minn = min(sum, minn);
}

int main()
{
    cin >> N >> M >> X;
    C.resize(N);
    A.resize(N, vll(M));
    rep(i, N) {
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }

    rep(i, (1ll<<N)) {
        update_minn(i);
    }

    if (minn == inf) {
        cout << -1 << endl;
    } else {
        cout << minn << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			long L = in.nextInt();
			long t = in.nextInt();
			t *= 2;
			L *= 2;
			List<Long> aa = new ArrayList<>();
			List<Long> bb = new ArrayList<>();
			int firstA = -1;
			for (int i = 0; i < n; i++) {
				long x = in.nextInt();
				int w = in.nextInt();
				x *= 2;
				if (w == 1) {
					aa.add(x);
					if (firstA < 0) {
						firstA = i;
					}
				} else {
					bb.add(x);
				}
			}
			long[] a = toArray(aa);
			long[] b = toArray(bb);

			long[] ans = new long[n];
			int p = 0;
			for (long x : a) {
				ans[p++] = (x + t) % L;
			}
			for (long x : b) {
				ans[p++] = ((x - t) % L + L) % L;
			}

			if (a.length > 0 && b.length > 0) {
				int s = firstA;
				for (long x : b) {
					long d = ((x - a[0]) % L + L) % L;
					long numCollisions = 0;
					if (t - 1 < d / 2) {
						continue;
					}
					++numCollisions;
					numCollisions += (t - 1 - d / 2) / (L / 2);

					s = (int) ((s + numCollisions) % n);
				}

				// The point at a[0] had the number firstA.
				// It moved to (a[0] + t) mod L and changed its number to s.
				Arrays.sort(ans);
				int j = -1;
				for (int i = 0; i < ans.length; i++) {
					if (ans[i] == (a[0] + t) % L) {
						j = i;
						break;
					}
				}
				long[] nans = new long[n];
				for (int i = 0; i < n; i++) {
					nans[(s + i) % n] = ans[(j + i) % n];
				}
				ans = nans;
			}

			for (long x : ans) {
				out.println(x / 2);
			}
		}

		private long[] toArray(List<Long> lst) {
			long[] a = new long[lst.size()];
			for (int i = 0; i < a.length; i++) {
				a[i] = lst.get(i);
			}
			return a;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 46528
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b = IR(2)
    l = [i for i in [1,2,3]]
    for i in l:
        if i not in (a,b):
            print(i)
            return
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39408
#include<iostream>
#include<set>

using namespace std;

set<int> primes;

int main() {
    int n;

    for (int n=2; n<=123456*2; n++) {
        bool is_prime = true;
        for (set<int>::iterator iter=primes.begin(); iter!=primes.end(); iter++) {
            if ((*iter)*(*iter) > n) {
                break;
            }
            if (n%(*iter) == 0) {
                is_prime = false;
                break;
            }
        }
        if (is_prime) {
            primes.insert(n);
        }
    }
    while (true) {
        cin >> n;
        if (n == 0) {
            break;
        }
        int count = 0;
        for (int i=n+1; i<=2*n; i++) {
            if (primes.find(i) != primes.end()) {
                count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 2212
//テンプレ：

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
vector<ll>ck(200005);
vector<ll>to[200005];
int res = 0;

void dfs(ll v, ll p = -1){
  res++;
  ck[v] = 1;
  for(int i=0; i<to[v].size(); i++){
    int u = to[v][i];
    if(u == p)continue;
    if(ck[u]==1)continue;
    dfs(u,v);
  }
}

int main(){
  int n,m,mx=0;
  cin >> n >>m;
  for(int i=0; i<m; i++){
    int x,y;
    cin >> x >> y;
    x--;y--;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  
  for(int i=0; i<n; i++){
    if(ck[i] == 1)continue;
    res = 0;
    dfs(i);
    mx = max(mx,res);
  }
  cout << mx << endl;
}
    
    
    


Measured memory_bytes: 25056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
  char b;
  cin>>b;
  char ans='0';
  if(b=='A'){
      ans='T';
  }
  else if(b=='T'){
      ans='A';
  }
  else if(b=='C'){
      ans='G';
  }
  else if(b=='G'){
      ans='C';
  }
 
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int nowx = 0, nowy = 0;
    int nowt = 0;
    for(int i = 1; i <= n; ++i) {
        int t, x, y;
        scanf("%d%d%d", &t, &x, &y);
        int step = abs(nowx - x) + abs(nowy - y);
        int time = t - nowt;
        int op = step - time;
        if(op  > 0) {
            cout <<"No";
            return 0;

        }
        else {
            if(abs(op) % 2 == 1) {
                cout << "No";
                return 0;
            }
            nowx = x, nowy = y;
            nowt = t;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ref(i,n) for(int i=0;i<n;i++)
using namespace std;
int a,b,c,d;
int main()
{
    cin>>a>>b>>c>>d;
    if(d<=a) cout<<d;
    else if(d<=(a+b)) cout<<a;
    else cout<<a-(d-a-b);
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>

int main()
{
    int t,a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b)
    {
        t=a;
        a=b;
        b=t;
    }
    if(b>c)
    {
        t=b;
        b=c;
        c=t;
    }
    if(a>b)
    {
        t=a;
        a=b;
        b=t;
    }
    printf("%d\n",b-a+c-b);
    return 0;
}


Measured memory_bytes: 128
<?php
$n=fgets(STDIN);
$numbers=explode(' ',fgets(STDIN));

$count = 0;
while(true) {
    $allEven = true;
    foreach( $numbers as $number ) {
        if($number %2 !== 0) {
            $allEven = false;
            break;
        }
    }
    if ($allEven) {
        $newNumbers = [];
        foreach( $numbers as $number ) {
            $newNumbers[] = $number / 2;
        }
        $numbers = $newNumbers;
        $count = $count + 1;
    } else {
        break;
    }
}
echo($count);


Measured memory_bytes: 4728
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    long long a, b, ans = 0, k;
    vector<long long> a_div;
    cin >> a >> b;

    for(long long i = 1; i*i <= a; i++){
        if(a % i != 0) continue;
        a_div.push_back(i);
        if(a/i != i) a_div.push_back(a/i);
    }
    for(long long i: a_div){
        if(b % i == 0){
            k = 1;
            for(long long j = 2; j*j <= i; j++){
                if(i % j == 0){
                    k = 0;
                    break;
                }
            }
            if(k == 1) ans++;
        }
    }

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

Measured memory_bytes: 384
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int[] path = new int[6];
      
        for(int i = 0; i < 6; i++){
          path[i] = sc.nextInt();
        }
      
        int c1 = 0;
        int c2 = 0;
        int c3 = 0;
        int c4 = 0;
      
        for(int i = 0; i < 6; i++){
          switch(path[i]){
            case 1: c1++;
              break;
            case 2: c2++;
              break;
            case 3: c3++;
              break;
            case 4: c4++;
              break;
          }
        }
 
        if((c2 == 2 && c3 == 2) || (c1 == 2 && c4 == 2)){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
	}
}

Measured memory_bytes: 35888
#include<iostream>
using namespace std;
int main(){
  
  //変数
  string s;
  
  //入力
  cin >>  s; 
  
  //略称
  string ans;
  string size;
  
  size = to_string( s.size() - 2 );
  ans = s[0] + size + s[s.size() - 1];
  
  //出力
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a + 1), t(b + 1);
    constexpr ll inf = 1e+15;
    s[0] = -inf;
    for(int i = 1; i <= a; ++i) cin >> s[i];
    s.emplace_back(inf);
    t[0] = -inf;
    for(int i = 1; i <= b; ++i) cin >> t[i];
    t.emplace_back(inf);
    for(int i = 0; i < q; ++i){
        ll x;
        cin >> x;
        int p1 = lower_bound(s.begin(), s.end(), x) - s.begin();
        int p2 = lower_bound(t.begin(), t.end(), x) - t.begin();
        ll ans = min(max(s[p1], t[p2]) - x, x - min(s[p1 - 1], t[p2 - 1]));
        chmin(ans, min(s[p1] * 2 - x - t[p2 - 1], x - s[p1 - 1] * 2 + t[p2]));
        chmin(ans, min(t[p2] * 2 - x - s[p1 - 1], x - t[p2 - 1] * 2 + s[p1]));
        cout << ans << endl;
    }
}

Measured memory_bytes: 2912
n = gets.to_i
hs = gets.chomp.split.map(&:to_i)
ans = 0
cnt = 0

n.times do |i|
  if i != n - 1 && hs[i] >= hs[i+1]
    cnt += 1
  else
    ans = cnt if ans < cnt
    cnt = 0
  end
end

puts ans

Measured memory_bytes: 11036
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>b)
	cout<<"a > b"<<endl;
	else if(a<b)
	cout<<"a < b"<<endl;
	else
	cout<<"a == b"<<endl;
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b , c;
  cin >> a >> b;
  c = a * b;
  if(c%2 == 1){
    cout << "Odd" <<endl;
  }
  else{
    cout << "Even" <<endl;
  }
}

Measured memory_bytes: 256
using System;

namespace Treasure_Hunt
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0;
            int r = 90;
            double x = 0;
            double y = 0;

            while (true)
            {
                string input = Console.ReadLine();
                if (input.Equals("0,0"))
                {
                    break;
                }

                string[] temp = input.Split(',');
                n = int.Parse(temp[0]);
                y += Math.Sin(r* Math.PI/180) * n;
                x += Math.Cos(r*Math.PI/180) * n;
                r -= int.Parse(temp[1]);

            }

            Console.WriteLine((int)x);
            Console.WriteLine((int)y);
        }
    }
}



Measured memory_bytes: 15888
/*
***AUTHOR***
*ADVAITVD99*
*/
#include<bits/stdc++.h>

using namespace std;

int main(){
	clock_t tim;
    tim = clock();
	const long long MOD=1e9+7;
    {
		string s;
		cin>>s;
		if(s[s.size()-1]=='s'){
			s=s+"es";
		}else{
			s=s+"s";
		}
		cout<<s<<endl;
	}

    //tim = clock() - tim;
    //double time_taken = ((double)tim)/CLOCKS_PER_SEC;
    //cout<< fixed << setprecision(3) << time_taken << "seconds" <<endl;

	return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define For(i , j , k) for (int i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)
#define Fordown(i , j , k) for (int i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb push_back
#ifdef hany01
#define debug(...) fprintf(stderr , __VA_ARGS__)
#else
#define debug(...)
#endif 
using namespace std;
typedef long long LL;

inline void file()
{
#ifdef hany01 
	freopen("a.in" , "r" , stdin);
    freopen("a.out" , "w" , stdout);
#endif
}

char c_;
int _ , __;
inline int read()
{
    for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar())
            if (c_ == '-')
                __ = -1;
    for ( ; isdigit(c_) ; c_ = getchar())
        _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

LL gcd(LL a , LL b) { return a ? gcd(b % a , a) : b; }

LL n , a , b , c , x , y , z , N , M , SQ;

int main()
{
	file();
    n = read();
    if (n % 2 == 0)
    {
        cout << n << ' ' << n << ' ' << n / 2 << endl;
    }
    else
    {
        for (c = n / 4 + 1 ; c <= 3500 ; ++ c)
        {
            x = 4 * c - n;
            y = c * n;
            z = gcd(x , y);
            x /= z;
            y /= z;
            for (LL i = 1 ; i * x <= 7000 && i * y <= 3500 * 3500 ; ++ i)
            {
                M = i * x;
                N = i * y;
                if (M * M < 4 * N)
                    continue;
                SQ = sqrt(M * M - 4 * N);
                a = (M + SQ) / 2;
                b = (M - SQ) / 2;
                if (a <= 0 || b <= 0)
                    continue;
                if ((4 * c - n) * a * b == c * (a + b) * n)
                {
                    cout << a << ' ' << b << ' ' << c << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    string s,t;
    cin>>n>>s>>t;
    string ss,tt;
    int memo=0;
    for(int i=1;i<=n;i++){
        ss=s.substr(n-i,i);
        tt=t.substr(0,i);
        if(ss==tt){
            memo=i;
            
        }
    }
    //cout<<memo<<endl;
    string x="";
    for(int i=0;i<n-memo;i++){
        x+=s[i];
    }
    //cout<<t<<endl;
    x+=t;
    cout<<x.size()<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <typeinfo>
#include <stdlib.h>
#include <deque>

#define ll long long

using namespace std;

ll calc_diff(deque<ll> deq){
    ll diff=0;
    for(ll i=0; i<deq.size()-1; i++){
        diff += abs(deq[i]-deq[i+1]);
        //cout << "diff= "<<diff<<endl;
    }
    return diff;
}

int main(int argc, char* argv[]){
    ll n,k,min=0,max=0;
    deque<ll> a,ret;
    cin >> n;
    for(ll i=0; i<n; i++){
        cin >> k;
        a.push_back(k);
    }
    sort(a.begin(), a.end());
    ll i=0;
    while(1){
        if (a.size()==0){
            break;
        }
        min=a.front();
        a.pop_front();
        if (a.size()==0){
            //cout << "i= "<< i <<"min: "<<min<< endl;            
            if (abs(ret[0]-min)>abs(ret.back()-min)){
                ret.push_front(min);
            }else{
                ret.push_back(min);
            }
            break;
        }
        max=a.back();
        a.pop_back();
        if(i%2==0){
            ret.push_front(min);
            ret.push_back(max);
        }else{
            ret.push_front(max);
            ret.push_back(min);
        }
        i++;
        //cout << "i= "<< i <<"min: "<<min<<" max "<<max<< endl;
    }
    ///calc diff
    ll answer = calc_diff(ret);
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 1920
import itertools

INF = 10**10
N, M, R = map(int, input().split())
*r, = map(int, input().split())
r = [v-1 for v in r]

g = [[INF]*N for _ in range(N)]
for i in range(N):
    g[i][i] = 0

for m in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c

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

ans = INF
for rs in itertools.permutations(r):
    cost = 0
    for i in range(len(rs)-1):
        cost += g[rs[i]][rs[i+1]]
    if cost < ans:
        ans = cost

print(ans)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

    int n, d;
    cin >> n >> d;

    cout << ceil((double)n / (2 * d + 1)) << endl;
    return 0;
}

Measured memory_bytes: 256
CH = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2,1,2,1]
N = int(input())
X = input()
s = 0
a = 1
A = []
B = []
for x in X:
    if x == "1":
        s += 1
for i in range(N):
    A.append(a)
    a = a*2 %(s+1)
a = 1
num = int(X,2)
num1 = num%(s+1)
if s > 1:
    num2 = num%(s-1)
    for i in range(N):
        B.append(a)
        a = a*2 %(s-1)
for i in range(N):
    if int(X[i])==1:
        p = s-1
        if p == 0:
            print(0)
            continue
        x = (num2-B[N-1-i])%p
        if x > 20:
            y = x%sum(map(int,list(bin(x))[2:]))
            print(2+CH[y])
        else:
            print(1+CH[x])
    else:
        p = s+1
        x = (num1+A[N-1-i])%p
        if x > 20:
            y = x%sum(map(int,list(bin(x))[2:]))
            print(2+CH[y])
        else:
            print(1+CH[x])

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 3e2 + 5;
const int mod = 1e9 + 7;

int f[maxn][maxn][maxn];
int n ,m;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    f[0][1][1] = 1;
    for(int i = 0 ; i < m ; ++i){
        for(int j = 1 ; j <= n ; ++j){
            for(int t = 1 ; t <= j ; ++t){
                auto add = [&](int & x , int y){
                    x += y;if(x>=mod)x-=mod;
                };
                add(f[i + 1][j + 1][t] , (ll)f[i][j][t] * (n - j) % mod);//
                add(f[i + 1][j][t] , (ll)f[i][j][t] * (j - t) % mod);
                add(f[i + 1][j][j] , (ll)f[i][j][t] * t % mod);
            }
        }
    }
    cout << f[m][n][n];
}


Measured memory_bytes: 110464
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    x = ni()

    for a in range(-200,200):
        for b in range(-200,200):
            if a**5-b**5 == x:
                print(a,b)
                exit(0)




if __name__ == '__main__':
    main()


Measured memory_bytes: 72912
using System;
using System.Linq;

namespace AtCoder.Contests.Abc176
{
    public class Step
    {
        public static void Main()
        {
            Console.ReadLine();
            string input2 = Console.ReadLine();

            if (String.IsNullOrEmpty(input2)) { return; }

            var items = input2.Split(' ')
                .Select(x => Int32.Parse(x));
            int p = 0;
            long sum = 0;

            foreach (var item in items)
            {
                if (item < p)
                {
                    sum += p - item;
                }
                else
                {
                    p = item;
                }
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 46244
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,q) = get!(usize, usize);
    let ab = get!(usize,usize; n-1);
    let px = get!(usize, usize; q);

    let mut count = vec![0; n+1];
    for (p, x) in px {
        count[p] += x;
    }
    let mut nodes = vec![Vec::new(); n+1];
    for (a,b) in ab {
        nodes[a].push(b);
        nodes[b].push(a);
    }
    
    let mut queue = VecDeque::new();
    let mut visited = vec![false; n+1];
    queue.push_back(1);
    visited[1] = true;
    while let Some(node) = queue.pop_front() {
        for &next in &nodes[node] {
            if visited[next] {
                continue;
            }
            count[next] += count[node];
            queue.push_back(next);
            visited[next] = true;
        }
    }
    for c in count.into_iter().skip(1) {
        print!("{} ",c);
    }
    println!("");
}


Measured memory_bytes: 28980
#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> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end());

    float ans = v[0];
    rep(j, N-1){
        ans = (ans+v[j+1])/2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    int K;
    cin >> K;
    int A,B;
    cin >> A >> B;
    for(int i=A; i<=B; i++){
        if(i%K == 0){
            cout <<"OK" << endl;
            return 0;
        }
    }
    cout << "NG" << enld;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

double x[5] = {0, 0.25, 0.5, 1, 2};
ll n, c[5], ans = 1e9, rs;

void rec(double t, ll rs = 0) {
    if (t == 0) {
        ans = min(ans, rs);
        return;
    }
    if (t < 0)
        return;
    for (int i = 1; i <= 4; i++) {
        rec(t - x[i], rs + c[i]);
    }
}

int main() {
    cin >> c[1] >> c[2] >> c[3] >> c[4];
    cin >> n;
    if (n >= 2) {
        rec(2);
        rs = (n / 2) * ans;
        n %= 2;
    }
    if (n == 1) {
        ans = 1e9;
        rec(1);
        rs += ans;
    }
    cout << rs;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"strings"
)

func lib_MaxInt(values ...int) (max int, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	max = values[0]
	for _, value := range values {
		if max < value {
			max = value
		}
	}
	return
}
func lib_MustMaxInt(values ...int) (max int) {
	max, err := lib_MaxInt(values...)
	if err != nil {
		panic(err)
	}
	return max
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var S string
	scanner.Scan()
	S = scanner.Text()
	fmt.Println(solve(S))
}
func solve(S string) int {
	maxCnt := 0
	for i, s := range S {
		cnt := 0
		if !strings.ContainsRune("ACGT", s) {
			continue
		}
		for _, s2 := range S[i:] {
			if strings.ContainsRune("ACGT", s2) {
				cnt++
			} else {
				break
			}
		}
		maxCnt = lib_MustMaxInt(maxCnt, cnt)
	}
	return maxCnt
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

ll dp[10010];

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

    ll H, N;
    cin >> H >> N;
    Vl A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }

    fill(begin(dp), end(dp), L_INF);
    dp[0] = 0;

    ll ans = L_INF;
    for (int h = 0; h < H; h++) {
        if (dp[h] == L_INF) continue;
        for (int i = 0; i < N; i++) {
            if (h + A[i] < H) {
                dp[h + A[i]] = min(dp[h + A[i]], dp[h] + B[i]);
            }
            else {
                ans = min(ans, dp[h] + B[i]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {

	string s; cin >> s;
	int k; cin >> k;
	
	vector<string> c;
	for (int count = 1; count <= k; count++) {
		for (int j = 0; j < s.size()- count + 1; j++) {
			c.push_back(s.substr(j, count));
		}	
	}

	sort(c.begin(), c.end());
	c.erase(unique(c.begin(), c.end()), c.end());

	cout << c[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[33]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cin>>n;
	cout<<a[n]<<endl;
	return 0;
}


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

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(n: i32, k: i32, x: i32, y: i32) -> i32 {
    if n > k {
        x * k + (n - k) * y
    } else {
        x * n
    }
}

fn main() {
    input!(n: i32, k: i32, x: i32, y: i32);
    println!("{}", solve(n, k, x, y));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int H,W,K;
int a[66][33];
int b[33];
int ans;

int main(){
	scanf("%d%d%d" , &H , &W , &K);
	repm(i,H,0){
		repp(j,0,W){
			char c;
			scanf(" %c" , &c);
			a[i][j] = c - '0';
		}
	}
	repm(z1,H,0){
	repp(z2,0,W){
		int p = 0;
		int q = 1;
		int f = 1;
		a[z1][z2] *= -1;
		while(q > 0){
			q = 0;
			fill(b,b+W,0);
			repp(i,0,H){
				int x = 0;
				int y = 0;
				repp(j,0,W){
					++b[j];
					while(a[b[j]][j] < 0) ++b[j];
					if(x != a[b[j]][j]){
						if(x > 0 && j - y >= K){
							q += x * (j - y);
							repp(e,y,j){
								a[b[e]][e] *= -1;
							}
						}
						x = a[b[j]][j];
						y = j;
					}
				}
				if(x > 0 && W - y >= K){
					q += x * (W - y);
					repp(e,y,W){
						a[b[e]][e] *= -1;
					}
				}
			}
			p += f * q;
			f *= 2;
		}
		repm(i,H,0){
			repp(j,0,W){
				a[i][j] = abs(a[i][j]);
			}
		}
		ans = max(ans , p);
	}
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 128
S = input()
oddblack, oddwhite = 0,0
evenblack, evenwhite = 0,0
for i,x in enumerate(S):
    if i % 2 == 1:
        if x == '0':
            oddblack += 1
        else:
            oddwhite += 1
    else:
        if x == '0':
            evenblack += 1
        else:
            evenwhite += 1

answer = min(oddblack + evenwhite , oddwhite + evenblack)
print(answer)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    int n=s.size();
    int res =0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            string sub = s.substr(i,j-i+1);
            int num =sub.size();
            bool flg = true;
            for(int k=0;k<num;k++){
                char c = sub.at(k);
                if(c!='A'&&c!='C'&&c!='G'&&c!='T'){
                    flg=false;
                    break;
                }
            }
            if(flg) res = max(res,num);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

# 多次元配列
# dp = [[0] * 3 for _ in range(5)]

# 入力を受け取る
n, m = map(int, input().split())

print(n * (n - 1) // 2 + m * (m - 1) // 2)
# 出力


Measured memory_bytes: 3828
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

#　これだとダメ
# for a in range(A+1):
#     x = X - a*500
#     for b in range(B+1):
#         x -= b*100
#         for c in range(C+1):
#             x -= c*50
#             print(a,b,c,x)
#             if x == 0:
#                 ans += 1

# これはOK
# for a in range(A+1):
#     for b in range(B+1):
#         for c in range(C+1):
#             if 500*a+100*b+50*c == X:
#                 ans += 1


# こう書くとfor文一回省ける

for a in range(A+1):
    if 500 * a > X:
        break
    for b in range(B+1):
        if 500 * a + 100 * b > X:
            break
        x = X - 500*a -100*b
        if x%50 == 0:
            if x//50 <= C:
                ans += 1

print(ans)

#


Measured memory_bytes: 9096
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  string s;
  cin >> s;
  ll n = SZ(s);
  map<int, int> mp;
  int id = 0;
  int id2 = 0;
  mp.emplace(0, 0);
  rep(i, n){
    int c = s[i]-'a';
    id ^= (1 << c);
    if(!mp.count(id)){
      mp[id] = MOD;
    }
    rep(j, 26){
      id2 = id ^ (1 << j);
      if(mp.count(id2))
        chmin(mp[id], mp[id2]+1);
    }
  }
  print(max(1, mp[id]));
}


Measured memory_bytes: 9876
<?php
$n = trim(fgets(STDIN));
$tmp = trim(fgets(STDIN));
$arr  = explode(" ", $tmp);

sort($arr);

$ans =$arr[0];
for($i =1 ; $i<$n;$i++) {
  $ans=($ans+$arr[$i])/2;
}

echo $ans;

Measured memory_bytes: 4728
#include<stdio.h>

int n,S[100000];

int binarySearch(int);

int main(){
  int i, q, count=0, key, T[50000];
  
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&T[i]);

  for(i=0;i<q;i++){
    key=T[i];
    if(binarySearch(key)==1)count++;
  }
  printf("%d\n",count);
  
  return 0;
}

int binarySearch(int key){
  int left=0, right=n, mid;
  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key)return 1;
    else if(key>S[mid])left=mid+1;
    else right=mid;
  }
  return 0;
}

Measured memory_bytes: 1184
input_lines = readlines
H,W = input_lines[0].split(' ').map!(&:to_i)
squares = []
H.times do |i|
  squares.push(input_lines[i+1].split('').take(W))
end
dx = [1,0,-1,0,1,1,-1,-1]
dy = [0,-1,0,1,1,-1,-1,1]
for i in 0...H do
  for j in 0...W do
    next if squares[i][j] == '#'
    num = 0
    for d in 0..7 do
      ni = i + dy[d]
      nj = j + dx[d]
      next if ni < 0 || ni >= H
      next if nj < 0 || nj >= W
      num+=1 if squares[ni][nj] == '#'
    end
    squares[i][j] = num.to_s
  end
end
H.times do |i|
  puts squares[i].join
end


Measured memory_bytes: 2172
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
ll a,b,n;
int main(){
    scanf("%lld%lld%lld",&a,&b,&n);
    ll x=min(n,b-1);
    printf("%lld\n",a*x/b-a*(x/b));
    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define int long
#define endl "\n"
signed main()
{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cout.tie(NULL);
		int a,b,c,k;
		cin>>a>>b>>c>>k;
		int co=0;
		while(a>=b)
				b*=2,++co;
		while(b>=c)
				c*=2,++co;
		if(co<=k)
				cout<<"Yes";
		else
				cout<<"No";
				 








		return 0;	
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

bool is_kai(std::string s) {
	std::string t = s;
	std::reverse(t.begin(), t.end());
	return s == t;
}

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	puts(is_kai(s) && is_kai(s.substr(0, n / 2)) && is_kai(s.substr(n / 2 + 1, n)) ? "Yes" : "No");
	return 0;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;
map<string, int> m;

bool comp(string a, string b)
{
    return m[a] > m[b];
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    vector<string> v;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    int mx = -1;
    for(map<string,int>::iterator a = m.begin(); a != m.end(); a++)
    {
        mx = max(mx, a->second);
    }

    for(map<string,int>::iterator a = m.begin(); a != m.end(); a++)
    {
        if(a->second == mx)
        {
            v.PB(a->first);
        }
    }

    for(int i=0; i<v.size(); i++)
    {
        cout << v[i] << "\n";
    }

    return 0;
}



Measured memory_bytes: 25584
package main

import(
	"fmt"
	"sort"
)

const MAX = 1000

func main(){
	var N,K int
	var sum int
	//var p []int
	
	fmt.Scan(&N)
	fmt.Scan(&K)
	
	p := make([]int,N)
	for i := 0; i < N; i++ {
		fmt.Scan(&p[i]);
	}
	sum = 0
	sort.Ints(p)
	for i := 0; i < K; i++ {
		sum += p[i]
	}
	fmt.Println(sum)
}

Measured memory_bytes: 1888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (auto &e : a)
    cin >> e;
  sort(a.begin(), a.end(), greater<ll>());
  vector<ll> ans;
  for (ll i = 0; i < a.size(); ++i)
  {
    if (a[i] == a[i + 1])
    {
      if (!(a.size() % 2 != 0 && i == a.size() - 1))
      {
        ans.push_back(a[i]);
        i++;
      }
    }
  }
  if (ans.size() < 2)
  {
    cout << 0 << endl;
  }
  else
    cout << ans[0] * ans[1] << endl;

  return 0;
}


Measured memory_bytes: 1660
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	ints := readIntArray()
	a, b, c, k := ints[0], ints[1], ints[2], ints[3]

	max := 0
	if a >= k {
		max = k
	}else if a+b >= k {
		max = a
	}else if a+b+c >= k {
		max = a - (k - a - b)
	}
	fmt.Println(max)
}

func readLine() string {
	if sc.Scan() {
		return sc.Text()
	}
	return "error"
}

func readStringArray() []string {
	return strings.Split(readLine(), " ")
}

func readIntArray() []int {
	a := readStringArray()
	ints := make([]int, len(a))
	for i, s := range a {
		n, err := strconv.Atoi(s)
		if err != nil {
			panic(err)
		}
		ints[i] = n
	}
	return ints
}

func readInt() int {
	n, err := strconv.Atoi(readLine())
	if err != nil {
		panic(err)
	}
	return n
}


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


public class Test
{	
    public static void Main()
	{
	    int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	    
	    int a = nums[0];
	    int b = nums[0]/15;
	    
	    Console.WriteLine(a*800 - b*200);
	    
	}
}

Measured memory_bytes: 13268