akhauriyash/Code-Regression huggingface dataset:
N,X = map(int,input().split())
L = [1]
for i in range(N) :
    l = L[-1] + 2**(2+i)
    L.append(l)
    
def dp(n,x) :
    if x == 0 :
        return 0
    elif n == 0 :
        return 1
    elif n >= 1 :
        if x == 1 :
            return 0
        elif x <= L[n-1]+1 :
            return dp(n-1,x-1)
        elif x == L[n-1]+2 :
            return dp(n-1,L[n-1])+1
        elif x <= L[n-1]*2+2 :
            return dp(n-1,L[n-1])+1 + dp(n-1,x-L[n-1]-2)
        else :
            return dp(n-1,L[n-1])*2+1
        
print(dp(N,X))


Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
b = []

if n % 2 == 0:
    for i in range(n-1, -1, -2):
        b.append(a[i])
    for i in range(0, n, 2):
        b.append(a[i])
    print(*b)
else:
    for i in range(n-1, -1, -2):
        b.append(a[i])
    for i in range(1, n, 2):
        b.append(a[i])
    print(*b)

Measured memory_bytes: 26180
def findlong(a):
    a+=[0]
    l = 0
    c = []
    j = 0
    for i in range(len(a)):
        if(a[i]!=0):
            l+=1
            j = i
        else:
            c.append([l,j])
            l = 0
    return max(c)
n = int(input())
a = list(map(int,input().split()))
l = 0
while(True):
    if(len(set(a))==1 and a[0]==0):
        break
    k = findlong(a)
    del a[-1]
    z = [k[1]-k[0]+1,k[1]]
    for i in range(z[0],z[1]+1):
        a[i]-=1
    l+=1
print(l)


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** power % mod ( natural numbers )
ll PowMod( ll base, ll power, ll mod ){
    if( power == 0 ) return 1;
    // O( log(Power) )
    ll Phalf = power / 2;
    ll half = PowMod(base, Phalf, mod);
    if( power % 2 ){
        return base * PowMod(base, power - 1, mod) % mod;
    }else{
        return half * half % mod;
    }
}
// }}}

// Comb( n, r, modulo ) return nCr % modulo {{{
// Comb(ination) = nCr % mod ( natural number )
ll Comb( ll n, ll r, ll mod){
    if( n < r ) return Comb(r,n,mod);
    ll Upper = 1;
    ll Lower = 1;
    for(ll i = 0; i < r; i++){
        Upper = Upper * (n-i) % mod;
        Lower = Lower * (i+1) % mod;
    }
    // Return (Upper / Lower)
    ll ret = Upper * PowMod(Lower,mod-2,mod) % mod;
    return ret;
}
// }}}

ll mod = 1000000007;

int main() {

    int n; int m;
    Scd2(n,m);

    int remain = m;
    ll ans = 1;
    int cnt = 0;

    for( int i = 2; i <= remain; i++){
        cnt = 0;
        while( remain % i == 0 ){
            remain /= i;
            cnt++;
        }
        if( cnt ){
            ans = ans * Comb(cnt+n-1,n-1,mod) % mod;
        }
    }

    printf ("%llu\n", ans);

    return 0;
}



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

/*1??´1???1??\????????°???????????\?????????????????¢??°*/
int calc(int y,int m,int d){
  return (y-1)*195+(y-1)/3*5 + (m-1)*20-(y%3==0 ? 0 : (m-1)/2) + d;
}

int main(void){
    int n,Y,M,D;
    int Millennium = calc(1000,1,1);
    cin>>n;
    while(n--){
        cin>>Y>>M>>D;
        cout<<Millennium-calc(Y,M,D)<<endl;
    }

    return 0;
}

Measured memory_bytes: 1160
from heapq import heappush, heappop
k = int(input())

heap = [(1,1)]
dist = [float("inf")]*k
while heap:
    cost, cur = heappop(heap)
    if dist[cur] <= cost:
        continue
    dist[cur] = cost
    # +1
    nxt = (cur+1)%k
    heappush(heap, (cost+1, nxt))
    # *10
    nxt = cur*10 % k
    heappush(heap, (cost, nxt))

print(dist[0])

Measured memory_bytes: 80204
//Author : Vipul Sharma

// LIBRARIES
#include <bits/stdc++.h>

// MACROS
#define ll long long 
#define ld long double
#define rep(i, a, b) for ( i = a; i < b; i++)
#define rev(i,b,a) for( i=b-1;i>=a;i--)
#define eqrep(i,a,b) for( i=1;i<=b;i++)
#define itrep(at) for (auto it = at.begin(); it != at.end(); it++)
#define ld long double
#define pb push_back
#define w(t) while (t--)
#define booster                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mod 1000000007
#define endl "\n"
# define INF 0x3f3f3f3f 
#define deb1(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << endl;
#define deb4(x, y, z, w) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << "\t" << #w << " : " << w << endl;
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

using namespace std;
long long cost = 1e18;



int main()
{
	
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    booster;
    ll n;
    cin>>n;
    cout<<(1000 - n % 1000) % 1000<<endl;
    return 0;
}

Measured memory_bytes: 3688
$arr=Array.new()
class BinaryTree
  attr_accessor :id,:parent,:sibling,:degree,:depth,:height,:type,:children
  def initialize(id,children,degree)
    @id=id
    @parent=-1
    @sibling=-1
    @degree=degree
    @height=0
    @children=children
    @type=(children==[-1,-1] ? 'leaf' :'internal node')
  end
  def print
    puts "node #{id}: parent = #{parent}, sibling = #{sibling}, degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
  end
  def setDepth
    children.each do |c|
      unless c==-1
        $arr[c].depth = depth + 1
        $arr[c].setDepth
      end
    end
  end
  def setHeight
    unless parent==-1
      $arr[parent].height=height+1 if $arr[parent].height<height+1
      $arr[parent].setHeight
    end
  end
end
n=gets.to_i
n.times do
  id,*children=gets.split.map(&:to_i)
  degree=2
  children.each do |e|
    degree-=1 if e==-1
  end
  $arr << BinaryTree.new(id,children,degree)
end
$arr.sort_by! do |e| e.id end
$arr.each do |ele|
  ele.children.each do |e|
    unless e==-1
      $arr[e].parent=ele.id
      $arr[e].sibling=(e==ele.children[0] ? ele.children[1] : ele.children[0])
    end
  end
end
$arr.each do |e|
  if e.parent==-1
    e.type='root'
    e.depth=0
    e.setDepth
  end
  e.setHeight if e.type=='leaf'
end
$arr.each do |e|
  e.print
end

Measured memory_bytes: 8708
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
const int N=1e5+50;
const int INF=0x3f3f3f3f;
typedef long long ll;
ll a[N];
int main()
{
    long long n,m;
    scanf("%lld%lld",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    ll ans=0,temp=0;
    for(int i=0;i<n;i++)
    {
        if(temp+a[i]<=m)
            temp=a[i];
        else
        {
            ans+=a[i]+temp-m;
            temp=a[i]-(a[i]+temp-m);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

namespace _028_ModeValue
{
	class Program
	{
		static void Main ( string[] args )
		{
			List<Pair> list = new List<Pair> (100);

			for (int lp = 1; lp <= 100; lp++)
			{
				Pair p = new Pair (lp, 0);
				list.Add (p);
			}

			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int inputNum = int.Parse (inputStr);
				list[inputNum - 1].Value++;
			}

			list = list.OrderByDescending (item => item.Value).ThenBy (item => item.Index).ToList ();

			int max = list[0].Value;

			int index = 0;
			while (list[index].Value == max)
			{
				Console.WriteLine (list[index].Index);
				index++;
			}
		}
	}
	class Pair
	{
		public Pair ( int index, int value )
		{
			this.Index = index;
			this.Value = value;
		}
		public int Index { set; get; }
		public int Value { set; get; }
	}
}

Measured memory_bytes: 9948
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

bool check(int x,int y) {
  if(x<0 || x>=6) return false;
  if(y<0 || y>=12) return false;
  return true;
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    string t[12];
    vector<char> s[6];
    rep(i,12) cin >> t[i];
    rep(i,6) {
      for(int j=11; j>=0; j--) s[i].pb(t[j][i]);
    }
    int ans=0;
    while(1) {
      bool ck=false;
      bool d[6][12],d2[6][12];
      memset(d,false,sizeof(d));
      memset(d2,false,sizeof(d2));
      rep(i,6) {
	rep(j,12) {
	  if(!d[i][j] && s[i][j]!='.' && s[i][j]!='O') {
	    queue<P> que,que2;
	    que.push(P(i,j));
	    que2.push(P(i,j));
	    d[i][j]=true;
	    while(!que.empty()) {
	      P p=que.front();
	      que.pop();
	      int nx=p.F,ny=p.S;
	      rep(k,4) {
		int x=nx+dx[k],y=ny+dy[k];
		if(check(x,y) && !d[x][y] && s[x][y]==s[i][j]) {
		  que.push(P(x,y));
		  que2.push(P(x,y));
		  d[x][y]=true;
		}
	      }
	    }
	    if(que2.size()>=4) {
	      ck=true;
	      while(!que2.empty()) {
		P p=que2.front();
		que2.pop();
		s[p.F][p.S]='.';
		d2[p.F][p.S]=true;
	      }	  
	    }
	  }
	}
      }
      if(ck) {
	rep(i,6) {
	  rep(j,12) {
	    if(s[i][j]=='O') {
	      rep(k,4) {
		int x=i+dx[k],y=j+dy[k];
		if(check(x,y) && d2[x][y]) {
		  s[i][j]='.';
		  break;
		}
	      }
	    }
	  }
	}
	rep(i,6) fill(remove(all(s[i]),'.'),s[i].end(),'.');
	ans++;
      } else break;
    }
    pr(ans);
  }
  return 0;
}


Measured memory_bytes: 1240
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b && b==c)
		printf("1\n");
	else if(a!=b && b!=c && a!=c)
		printf("3\n");
	else
		printf("2\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int t[110];
int v[210];
int l[110];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>t[i];
	for(int i=1;i<=n;i++)cin>>v[i];
	REP(i,110)l[i]=1e8;
	l[0]=0;
	l[n]=0;
	for(int i=0;i<100000;i++){
		for(int j=1;j<n;j++){
			l[j]=min(min(v[j],v[j+1]),min(l[j+1]+t[j+1],l[j-1]+t[j]));
		}
		for(int j=n-1;j>=0;j--){
			l[j]=min(min(v[j],v[j+1]),min(l[j+1]+t[j+1],l[j-1]+t[j]));
		}
	}
	//REP(i,n+1)cout<<l[i]<<endl;
	double ans=0;
	for(int i=1;i<=n;i++){
		if((v[i]-l[i-1])+(v[i]-l[i])<=t[i]){
			double a=t[i]-(v[i]-l[i-1])-(v[i]-l[i]);
			double tans=(double)a*v[i];
			tans+=(double)(l[i-1]+v[i])*(v[i]-l[i-1])/2;
			tans+=(double)(l[i]+v[i])*(v[i]-l[i])/2;
			ans+=tans;
		}else{
			double m=(double)(t[i]+l[i]+l[i-1])/2;
			double tans=0;
			tans+=(double)(l[i-1]+m)*(m-l[i-1])/2;
			tans+=(double)(l[i]+m)*(m-l[i])/2;
			ans+=tans;
		}
	}
	printf("%.15f",ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int , input().split()))
# dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2])
dp = [0 for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
print(dp[n-1])




Measured memory_bytes: 13980
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  	int k; cin >> k;
    string s; cin >> s;
  	for (int i = 0; i < min(k, int(s.size())); ++i) cout << s[i];
  	if (s.size() > k) cout << "...\n";
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

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

int main(void){
  int N;
  cin >> N;
  vector<string> s(N);  
  rep(i, N)
    cin >> s[i];

  //stringが今までにint回出てきたことを格納するtree
  unordered_map<string, int> freq;
  long long int ans = 0;
  
  rep(i, N){
    //文字列s[i]をソート
    sort(s[i].begin(), s[i].end());
    //文字列s[i]が既に出てきていればカウントを増やす
    //s[i]がs[j]のアナグラムであるとき，
    //今までにj = freq[ s[i] ]回出てきているため，それをansに加算
    ans += freq[ s[i] ]++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 17700
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

ll mod_pow(ll a, ll p)
{
	if (p == 0)return 1;
	else if (p == 1)return a;
	else if (p % 2 == 0)
	{
		ll h = mod_pow(a, p / 2);
		return h * h % mod;
	}
	else return (mod_pow(a, p - 1) * a) % mod;
}

vl fact;
vl fact_inv;

int main()
{
	int n, k; cin >> n >> k;
	vl a(n);
	fact.resize(n + 1);
	fact_inv.resize(n + 1);
	rep(i, n+1)
	{
		fact[i] = i <= 1 ? 1 : (fact[i - 1] * i) % mod;
		fact_inv[i] = mod_pow(fact[i], mod - 2) % mod;
		//fact_inv[i] = i<=1 ? 1 : fact_inv[i-1] * mod_pow(i, mod - 2) % mod;
	}
	//reps(i, n)cs(fact[i]); el;
	//reps(i, n)cs(fact_inv[i]); return 0;
	rep(i, n)cin >> a[i];
	sort(all(a));
	
	ll ans = 0;
	for (int i = k - 1; i < n; i++)
	{
		ll comb = ((fact[i] * fact_inv[i - k + 1] % mod) * fact_inv[k - 1]) % mod;
		ll tmp = a[i] * comb % mod;
		ans += tmp;
		ans %= mod;
	}
	for (int i = 0; i+k-1 < n; i++)
	{
		ll comb = ((fact[n-i-1] * fact_inv[n-i-k] % mod) * fact_inv[k - 1]) % mod;
		ll tmp = a[i] * comb % mod;
		ans -= tmp;
		ans = (ans + mod) % mod;
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int nums[N];
    int sum = 0;
    int MX = -1;
    for(int i = 0;i < N;i++){
        cin >> nums[i];
        MX = max(MX,nums[i]);
        sum += nums[i];
    }
    cout << ((MX < sum - MX) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void inp_str(int*);


int main(void) {

int input1[100];
inp_str(input1);

int N,K;
N=input1[0];
K=input1[1];

//printf("%d\n",N);
//printf("%d\n",K);


int ans=0;

ans=N-K+1;


printf("%d\n",ans);



    return 0;




}


void inp_str(int instr[]){
char *ptr;
int z,i,count;
char str[100]={'\0'};
char *ln;

fgets(str, 100, stdin); // 入力："123456\n"
ln = strchr(str, '\n'); /* 改行文字を検索 */
if (ln != NULL) { /* 改行が読み取られていたかどうか */
   *ln = '\0';    /* 改行文字を終端文字に置き換える */
}
else {            /* 入力ストリーム上に文字が残ってる場合 */
   while (1) {    /* 改行文字が読み取られるまで空読みする */
       z = getchar();
      if (z == '\n' || z == EOF) break;
   }
}
	count=0;
    ptr = strtok(str, " ");
    i = atoi(ptr);
    instr[count]=i;
    count=count+1;
    // 2回目以降
    while(ptr != NULL) {
        // strtok関数により変更されたNULLのポインタが先頭
        ptr = strtok(NULL, " ");
        // ptrがNULLの場合エラーが発生するので対処
        if(ptr != NULL) {
		    i = atoi(ptr);
    instr[count]=i;
    		count=count+1;
        }
    }
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a[200009], dp[200009],k;
ll f(int i) {
	if (i > n)return 1e9;
	else if (i == n)return 0;
	if (dp[i] != -1)return dp[i];
	ll ans= f(i + 1) + abs(a[i] - a[i + 1]);
	for(int j=2;j<=k;j++){
            ans=min(ans, f(i+j)+abs(a[i]-a[i+j]));
	}
	return dp[i] =ans;
}
int main() {
	memset(dp, -1, sizeof dp);
	cin >> n>>k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	cout << f(1) << endl;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;

#define sf scanf
typedef long long ll;

int main() {
	ll n; sf("%lld", &n);
	ll sum[200100];
	for(ll i=0; i<n; i++) {
		ll x; sf("%lld", &x);
		if (i==0) sum[i] = x;
		else sum[i] = sum[i-1]+x;
	}
	ll mini = LLONG_MAX;
	for(ll i=0; i<n-1; i++) {
		if (abs(sum[i] - (sum[n-1]-sum[i])) < mini) mini = abs(sum[i] - (sum[n-1]-sum[i]));
		// printf("%lld %lld\n", sum[i], sum[n-1]-sum[i]);
	}
	printf("%lld\n", mini);
}

Measured memory_bytes: 1664
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double[] v = new double[n];
		
		Arrays.setAll(v, i -> sc.nextDouble());
		Arrays.sort(v);
		
		double ave = (v[0] + v[1]) / 2.0;
		for (int i = 2; i < n; i++) {
			ave = (ave + v[i]) / 2.0;
		}
		
		System.out.println(ave);
		
	}
}


Measured memory_bytes: 28756
#include<bits/stdc++.h>
 
using namespace std;
 
const int N=200005,M=600005;
 
int n,h[N],nxt[M],to[M],R[M],m=1;
bool vi[M],ev[N];
inline void add(int u,int v){to[++m]=v,nxt[m]=h[u],h[u]=m,to[++m]=u,nxt[m]=h[v],h[v]=m;}
inline void chk(int u,int v){if(u==v+n)R[v]=1;if(v==u+n)R[u]=-1;}
void dfs(int x){for(int&i=h[x];i;i=nxt[i])if(!vi[i])vi[i]=vi[i^1]=true,chk(x,to[i]),dfs(to[i]);}
 
int main(){
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++){scanf("%d",&x);if(~x)add(x,i),vi[x]^=1,ev[x]^=1;else add(0,i);}
	for(int i=1,x;i<=n;i++){scanf("%d",&x);if(~x)add(x+n,i+n),vi[x]^=1;else add(0,i+n);}
	for(int i=1;i<=n;i++){if(vi[i])puts("IMPOSSIBLE"),exit(0);if(!ev[i])add(i,i+n);}
	puts("POSSIBLE"),dfs(1);for(int i=1;i<=n;i++)printf("%d%c",R[i]," \n"[i==n]);
	return 0;
}

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

int w, a, b;

void solve() {
    cin >> w >> a >> b;
    if(b < a) swap(a, b);
    cout << (b - a - w <= 0 ? 0 : b - a - w) << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3532
[X,K,D] = list(map(int,input().split()))

if abs(X) >= D*K:
    out=abs(X) -D*K

else:
    K2 = abs(X) // D
    ato = K-K2
    now = abs(X) - D*K2
    if ato % 2 ==0:
        out = now
    else:
        out = abs(now - D)

print(out)


Measured memory_bytes: 61600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

using Graf_char=vector<vector<char>>;
using Graf_int=vector<vector<int>>;
#define MAX 10000000

int main()
{
    int h,w,d;
    cin >> h >> w >> d;
    vector<P> a(h*w+1);
    int num;
    rep(i,h){
        rep(j,w){
            cin >> num;
            a[num]=mp(i+1,j+1);
        }
    }
    
    int q;
    cin >> q;
    vector<P> task(q);
    rep(i,q){
        cin >> task[i].first >> task[i].second;
    }
    vector<ll> power(q);
    int val,val_r;
    vector<ll> dist(h*w+1,0);
    rep(i,d+1){
        dist[i]=0;
    }
    FOR(i,h*w+1,d+1){
        int k=a[i-d].first;
        int l=a[i-d].second;
        int x=a[i].first;
        int y=a[i].second;
        dist[i]=dist[i-d]+(abs(x-k)+abs(y-l));
    }
    rep(i,q){
        val=task[i].first;
        val_r=task[i].second;
        power[i]=dist[val_r]-dist[val];
    }
    rep(i,q){
        cout << power[i] << endl;
    }

}

Measured memory_bytes: 6164
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};

int a[11][5]={
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}};

int main(){
    int h,k;cin >> h >> k;
    int cnt = 0;
    for (int i = 0; i < 11; i++) {
        for (int j = 0; j < 5; j++) {
            if(a[i][j] == k) cnt++;
        }
    }
    int ans = 0;
    for (int i = 0; i < (h + 9) % 11; i++) {
        for (int j = 0; j < 5; j++) {
            if(a[i][j] == k) ans++;
        }
    }
    cout << ans + (h - 2) / 11 * cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
#define N 2000
 
void solve(int,int);
 
int A[N], M[N], n,flag=0;
 
int main(){
  int i,q;
   
  scanf("%d",&n);
  for(i=0; i < n; i++){
    scanf("%d",&A[i]);
  }
   
  scanf("%d",&q);
  for(i=0; i < q; i++){
    scanf("%d",&M[i]);
  }
 
  for(i=0; i < q; i++){
    flag = 0;
    solve(0,M[i]);
    if(flag == 1){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
 
  return 0;
}
 
void solve(int i,int m){
  if(m == 0){
    flag = 1;
  }else if(i < n){
    solve(i+1,m-A[i]);
    solve(i+1,m);
  }
}

Measured memory_bytes: 584
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    a = nl()

    price = [1 if i in a else 0 for i in range(n)]

    print(min(sum(price[:x]), sum(price[x:])))


if __name__ == '__main__':
    main()

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  vector<int> vec(3);
  for(int i = 0; i < 3; i++) cin >> vec[i];
  int K;
  cin >> K;
  sort(vec.begin(), vec.end());
  cout << vec[0] + vec[1] + vec[2] * (int)pow(2, K) <<endl;
}

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


int main(void) {
	string str;
	getline(cin, str);
	int i = 0,c=0;
	while (*(str.c_str() + i) != '\0') {
      	if(*(str.c_str() + i)=='1')c++;
		i++;
	}
  printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

signed main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << t / a * b << endl;
	return 0;
}

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

list_str = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

ans = ''
for s in S:
  _ = list_str.index(s)
  next_index = _ + N
  if next_index >= 26:
    next_index =  next_index - 26
  ans += list_str[next_index]

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 5e5;

const ll mod = 998244353;

ll fact[N + 1];

ll int_pow(ll base, ll exp){
	if(!exp){
		return 1ll;
	} else if(exp & 1){
		return base * int_pow(base, exp - 1) % mod;
	} else {
		return int_pow(base * base % mod, exp >> 1);
	}
}

ll binom(ll n, ll k){
	return fact[n] * int_pow(fact[k] * fact[n - k] % mod, mod - 2) % mod;
}

int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
	ll n, a, b, k; cin >> n >> a >> b >> k;
	fact[0] = 1;
	rep(i, 1, n + 1){
		fact[i] = fact[i - 1] * i % mod;
	}
	ll res = 0;
	rep(i, 0, n + 1){
		if(k >= a * i and (k - a * i) % b == 0 and (k - a * i) / b <= n){
			res = (res + binom(n, i) * binom(n, (k - a * i) / b)) % mod;	
		}
	}
	cout << res << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;



int _gcd(int a,int b)
{
	return (b==0?a:_gcd(b,a%b));
}
bool cmp(int a,int b)
{
	return a>b;
}

int main()
{
	fast;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
	    int n;cin>>n;
	    int k;cin>>k;
	    vector<int> dp(n+1);
	    dp[0]=1;
	    for(int i=1;i<=n;++i)
	    {
	    	dp[i]=min(dp[i-1]*2,dp[i-1]+k);
			
		}
		cout<<dp[n]<<endl;	

	return 0;
	    
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			String line = scanner.nextLine();

			StringBuilder builder = new StringBuilder(line);
			while (true) {
				int num = builder.indexOf("@");
				if (num == -1) {
					break;
				}
				builder.replace(num, num + 3, getStr(num, builder));
			}
			System.out.println(builder);

		}
	}

	private static String getStr(int num, StringBuilder builder) {
		int a = builder.charAt(num + 1) - '0';
		StringBuilder b = new StringBuilder();
		String s = builder.substring(num + 2, num + 3);
		for (int i = 0; i < a; i++) {
			b.append(s);
		}
		return b.toString();
	}
}

Measured memory_bytes: 17116
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*   
*   文件名称：C.cpp
*   创 建 者：YaliKiWi
*   创建日期：2019年08月04日
*   描    述：
*
================================================================*/


#include<bits/stdc++.h>
using namespace std;
#define maxn 100000+10
int a[maxn],n;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(register int i=1;i<=n;i++)cin>>a[i];
	for(register int i=n;i>1;i--){
		if(a[i]<a[i-1])a[i-1]--;
	}
	for(register int i=2;i<=n;i++){
		if(a[i]<a[i-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 768
"use strict";

function compareFunc(a, b) {
  return a - b;
}
const main = arg => {
  const input = arg.trim().split("\n");
  const N = parseInt(input[0].split(" ")[0]);
  const M = parseInt(input[0].split(" ")[1]);
  if (N == M) {
    console.log("Yes");
  } else {
    console.log("No");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29636
a=int(input())
if a==-1:
    print("11")
    exit()
if a==0:print("0")
b=""
c=2
d=0
n=0
if a > 0:
    m=a
else:
    m=-a-1
while m >d:
    if (a-d-1)%c < c//2:
        b+="1"
    else :
        b+="0"
    c*=2
    n=1-n
    d=d+(3*d+1)*n
if a < 0:
    if b[-1]=="0":b=b[:-1]
    if (a-d-1)%c < c//2:
        b+="1"
    

print(b[::-1])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int d = a-b;
    int k = c-d;
    if(k<=0) k= 0;
    cout<<k;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int w = sc.nextInt();
    
    if(s>w){
      System.out.println("safe");
    }else{
      System.out.println("unsafe");
    }

  }
}


Measured memory_bytes: 35648
#include<stdio.h>
#include<stdlib.h>

int main(void){
	int from[200000],to[200000];
	int n,m,p,q,i,j,in;
	
	scanf("%d%d",&n,&m);
	in=0;
	for(i=0;i<200000;i++) to[i]=0;
	for(i=0;i<m;i++){
		scanf("%d%d",&p,&q);
		if(p==1) from[in++]=q;
		if(q==n) to[p]=1;
	}
	int flg=0;
	for(i=0;i<in;i++){
		if(to[from[i]]==1){
			flg=1;
			break;
		}
	}
	
	if(flg==1) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 1280
using System;
class aizu{
    public static int Main(){
        int i,n;
        string str;
        for(i=0; ;i++){
        	str = Console.ReadLine();
        	n = int.Parse(str);
        	if(n==0) break;
        	Console.WriteLine("Case {0}: {1}",i+1,n);
        }
        return 0;
    }
}



Measured memory_bytes: 19952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
	char c, d;
	int count = 0;
	cin >> c;
	while(cin >> d){
		if(c != d)
			count++;
		c = d;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<int> a(n+2);
    a[0] = 0;
    a[n+1] = 0;

    rep(i,n) cin >> a[i+1];

    vector<int> difi(n+1);
    ll sum = 0;
    rep(i,n+1){
        difi[i] = abs(a[i+1] - a[i]);
        sum += difi[i];
    }

    rep(i,n){
        cout << sum - (abs(a[i+1] - a[i]) + abs(a[i+2] - a[i+1])) + abs(a[i+2] - a[i]) << endl;
    }
}


Measured memory_bytes: 2048
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>
#pragma warning(disable : 4996)
#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
using namespace std;
typedef long long ll;

const int maxn = (int)1e5 + 13;
const ll INFL = 9223372036854775807;
const int INF = 2147483647;
const ll MOD = (int)1e9 + 9;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101;
const long double pi = 3.1415926535897932;



int main() {
	drobucs;
	
	ll n;
	cin >> n;
	ll sum = 100;
	int cnt = 0;
	while (sum < n) {
		cnt++;
		sum = (ll)((double)sum * 1.01);
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N];

bool ok(ll m) {
	deque<pl> S;
	S.push_back(pl(0, 0)); //at color
	S.push_back(pl(A[0], -1));
	rep(i, 1, N) {
		ll pre = A[i];
		while(!S.empty()) {
			auto p = S.back();
			if(p.fst >= A[i]) {
				MIN(pre, p.fst);
				S.pop_back();
			}
			else break;
		}
		while(!S.empty()) {
			auto p = S.back();
			if(p.sec == m - 1) {
				MIN(pre, p.fst);
				S.pop_back();
			}
			else break;
		}
		if(S.empty()) return false;
		else {
			auto p = S.back();
			ll at = p.fst, v = p.sec;
			if(v == -1) {
				S.pop_back();
				S.push_back(pl(at, 0));
			}
			else {
				if(at == pre - 1) S.pop_back();
				S.push_back(pl(pre - 1, v + 1));
				if(pre != A[i]) S.push_back(pl(pre, 0));
			}
			S.push_back(pl(A[i], -1));
		}
		// debug(i, vector<pl>(all(S)));
	}
	return true;
}

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	ll lv = 0, rv = (1ll << 40);
	while(rv - lv > 1) {
		ll m = (lv + rv) / 2;
		if(ok(m)) rv = m;
		else lv = m;
	}
	cout << rv << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
using P = pair<int, int>;
vector<vector<int>> mindist(vector<vector<char>> S, P start)
{
    const char ok = '.', ng = '#';
    const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

    int H = S.size(), W = S[0].size();
    vector<vector<int>> dist(H, vector<int>(W, -1));

    queue<P> q;
    q.emplace(start);
    int sx = start.second, sy = start.first;
    dist[sy][sx] = 0;
    while (!q.empty())
    {
        int x = q.front().second, y = q.front().first;

        q.pop();
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx and nx < W and 0 <= ny and ny < H and S[ny][nx] == ok and dist[ny][nx] == -1)
            {
                dist[ny][nx] = dist[y][x] + 1;
                q.emplace(ny, nx);
            }
        }
    }
    return dist;
}
int max(vvint dist)
{
    int M = 0;
    int h = dist.size(), w = dist[0].size();
    for (size_t i = 0; i < h; i++)
    {
        for (size_t j = 0; j < w; j++)
        {
            chmax(M, dist[i][j]);
        }
    }
    return M;
}
int main()
{
    int H, W;
    cin >> H >> W;
    auto S = make_v<char>(H, W);
    for (size_t i = 0; i < H; i++)
    {
        for (size_t j = 0; j < W; j++)
        {
            cin >> S[i][j];
        }
    }
    int ans = 0;
    for (size_t i = 0; i < H; i++)
    {
        for (size_t j = 0; j < W; j++)
        {
            if(S[i][j]=='.')
            chmax(ans, max(mindist(S, {i, j})));
        }
    }
    cout << ans;
    return 0;
}

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

int mod = 1e9 + 7;
int main() {
    int h, w;
    cin >> h >> w;

    char grid[h][w];
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> grid[i][j];
        }
    }

    int dp[h][w];
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            int x = 0, y = 0;
            if(i > 0) x = dp[i-1][j];
            if(j > 0) y = dp[i][j-1];

            if(i == 0 && j == 0) dp[i][j] = 1;
            else if(grid[i][j] == '.') dp[i][j] = (x + y) % mod;
            else dp[i][j] = 0;
        }
    }
    cout << (dp[h-1][w-1] + mod) % mod << endl;
}


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


N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, w = map(int, input().split())
    graph[a-1].append((b-1, w))
    graph[b-1].append((a-1, w))

def dfs(s):
    Ind = [0]*N
    stack = [s]
    Color = [0]*N
    while stack:
        p = stack[-1]
        if Ind[p] == len(graph[p]):
            stack.pop()
        elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]:
            Ind[p] += 1
        else:
            ch, w = graph[p][Ind[p]]
            Ind[p] += 1
            stack.append(ch)
            Color[ch] = Color[p]^(w%2)
    return Color

Color = dfs(0)
print(*Color, sep="\n")


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

using namespace std;

int n,arr[100005],mem[100005];

int dp(int pos){
    if(pos==n-1)return 0;
    if(pos>=n)return 100000;
    if(mem[pos]!=-1)return mem[pos];
    return mem[pos]=min(dp(pos+1)+abs(arr[pos]-arr[pos+1]),dp(pos+2)+abs(arr[pos]-arr[pos+2]));
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    memset(mem,-1,sizeof(mem));
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<dp(0);
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner in = new Scanner(System.in);

    int X = in.nextInt();   // 彼の最高レーティング
    
    if(X < 600){
        System.out.println(8);
    }else if(X < 800){
        System.out.println(7);
    }else if(X < 1000){
        System.out.println(6);
    }else if(X < 1200){
        System.out.println(5);
    }else if(X < 1400){
        System.out.println(4);
    }else if(X < 1600){
        System.out.println(3);
    }else if(X < 1800){
        System.out.println(2);
    }else {
        System.out.println(1);
    }
      
  }
}

Measured memory_bytes: 35660
def mul(m, v):
    ans = []
    for row in m:
        a = 0
        for i in range(len(row)):
            a += row[i] * v[i]
        ans.append(a)
    return ans


n, m = [int(i) for i in input().strip().split()]

matrix = []
vector = []

for _ in range(n):
    matrix.append([int(i) for i in input().strip().split()])

for _ in range(m):
    vector.append(int(input().strip()))

ans = mul(matrix, vector)

for e in ans:
    print(e)


Measured memory_bytes: 5980
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w,0));
    REP(i,h){
        REP(j,w){
            cin >> a[i][j];
        }
    }
    vector<vector<int>> d(h,vector<int>(w,INT_MAX));
    queue<P> q;
    
    REP(i,h){
        REP(j,w){
            if(a[i][j]=='#'){
                q.push(P(i,j));
                d[i][j]=0;
            }
        }
    }
    while(q.size()>0){
        
        P p = q.front();
        q.pop();
        
        REP(i,4){
            int ny = p.first +dy[i];
            int nx = p.second+dx[i];
            if(0<=nx&&nx<w&&0<=ny&&ny<h&&a[ny][nx]=='.'&&d[ny][nx]==INT_MAX){
                q.push(P(ny,nx));
                d[ny][nx]=d[p.first][p.second]+1;
            }
        }
        
    }
    int res = 0;
    REP(i,h){
        REP(j,w){
            chmax(res,d[i][j]);
        }
    }
    put(res);
    return 0;
}


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

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

  bool b;
  b = true;
  for (int i=0; i<(int)s.size(); i++){
    if((i+1)%2 == 1 && s.at(i) == 'L') b = false;
    if((i+1)%2 == 0 && s.at(i) == 'R') b = false;
  }
  
  if(b){
    cout << "Yes" << endl; 
  }else{
    cout << "No" << endl; 
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		for(int i = 1; i <= 1100 ; i++){
			if((int)(0.08*i) == a && (int)(0.1*i) == b ){
				System.out.println(i);
				return;
			}
		}

		System.out.println("-1");
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 1e+9;

int n, a[21], ans;

void dfs(int diff, int k)
{
    if (k == n)
    {
        ans = min(ans, abs(diff));
    }
    else
    {
        dfs(diff + a[k], k + 1);
        dfs(diff - a[k], k + 1);
    }
}

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

        ans = INF;

        dfs(0, 0);

        cout << ans << endl;
    }
}

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

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

int main() {
    int N; long long X;
    cin >> N >> X;
    vector<long long> x(N);
    for (long long &xi: x) cin >> xi;
    long long g = 0;
    for (long long xi: x) g = gcd(g, abs(xi - X));
    cout << g << endl;
    return 0;
}

Measured memory_bytes: 1024
<?php

// test
// echo 'please enter: ';
// $a = 0;
// fscanf(STDIN,"%s %s", $a, $b);
// var_dump($a, $b);

// 読み込み
// echo 'please enter: ';
$string = trim(fgets(STDIN));
//var_dump($string);

if (($string[2] === $string[3]) and ($string[4] === $string[5])) {
  echo "Yes";
} else {
  echo "No";
}

 ?>

Measured memory_bytes: 3828
#include <stdio.h>

int main(void) {
  int s;

  scanf("%d", &s);

  int h = s / (60 * 60);
  int m = s / 60 - h * 60;
  s -= h * (60 * 60) + m * 60;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}



Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
#define PI 3.14159265358979323846
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int N,D;
int Q;
int d[500005];
int q[500005];
int L[500005];
int dp[500005];


signed main(){
    cin>>N>>D;
    L[0]=D;
    for(int i=0;i<N;++i){
        cin>>d[i];
        L[i+1]=min(L[i],abs(L[i]-d[i]));
    }
    cin>>Q;
    for(int i=0;i<Q;++i)cin>>q[i];
    dp[N]=1;
    for(int i=N-1;i>=0;--i){
        if(dp[i+1]<=d[i]/2)dp[i]=dp[i+1];
        else dp[i] = dp[i+1]+d[i];
    }
    for(int i=0;i<Q;++i){
        if(L[q[i]-1]==0||L[q[i]-1]<dp[q[i]])cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }

}


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

struct node
{
    ll data;
    node *left, *right;
    node(ll data)
    {
        this->data = data;
        left = right = NULL;
    }
};
unordered_map<ll, list<ll>>ma;

ll h(node *head)
{
    if (head == NULL)
        return 0;
    else
    {
        ll lh = h(head->left);
        ll rh = h(head->right);
        return max(lh, rh) + 1;
    }
}
void spiral(node *root, ll level)
{
    if (root == NULL)
        return ;
    if (level & 1)
        ma[level].push_back(root->data);
    else
        ma[level].push_front(root->data);
    spiral(root->left, level + 1);
    spiral(root->right, level + 1);

}
// void inorder(node *head)
// {


// }

typedef long long ll;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output12.txt", "w", stdout);
#endif
    ll a, b, d;
    cin >> a >> b >> d;
    ll cnt = 0;
    for (ll i = a; i <= b; i++)
        if (i % d == 0)
            cnt++;

    cout << cnt;

    return 0;
}


Measured memory_bytes: 3628