akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <set>
#include "math.h"
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
VI A,dp;
int ans;


int main()
{

	cin >> N;
	A.resize(N);
	REP(i,N){
		cin >> A[i];
	}
	dp.resize(N);

	if(A[0]%2==0){
		dp[0] = 1;
	} else {
		dp[0] = 2;
	}

	FOR(i,1,N){
		if(A[i]%2==0){
			dp[i] = pow(3,i) + dp[i-1]*2;
		} else {
			dp[i] = pow(3,i)*2 + dp[i-1];
		}
	}

	cout << dp[N-1];
}




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

#define For(i, j, k) for (int i = j; i <= k; ++ i)

using namespace std;

const int N = 2e3 + 10;
int a[N], t[N], n, k, q, b[N];

int main() {

	scanf("%d%d%d", &n, &k, &q);
	For(i, 1, n) scanf("%d", a + i); a[++ n] = -1;

	int ans = INT_MAX;
	For(tt, 1, n) {
		int nw = a[tt], c = 0, lstps = 1;

		For(i, 1, n) if (a[i] < nw) {
			if (i - lstps < k) { lstps = i + 1; continue; }
			int cnt = 0;
			For(j, lstps, i - 1) b[++ cnt] = a[j];
		//	nth_element(b + 1, b + cnt - k, b + cnt + 1);
			sort(b + 1, b + 1 + cnt);
			For(j, 1, cnt - k + 1) t[++ c] = b[j];
			lstps = i + 1;
		}
	
		if (c < q) continue;
		//nth_element(t + 1, t + q, t + c + 1);
		sort(t + 1, t + 1 + c);
		ans = min(ans, t[q] - nw);
	}

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if (y + r <= H && y - r >= 0 && x + r <= W && x - r >= 0)
	{
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


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

void call(int n){
    int x, i = 1;
    do{
        x = i;
        if(x%3==0) cout<<" "<<i;
        else{
            do{
                if(x%10==3){
                    cout<<" "<<i;
                    break;
                }
                x/=10;
            }while(x);
        }
    }while(++i<=n);
    cout << endl;
}

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



Measured memory_bytes: 3136
import sys
sys.setrecursionlimit(10000)

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.size = [1]*n

    def find(self,a):
        if self.parent[a] == a:
            return a
        else:
            return self.find(self.parent[a])

    def unite(self,a,b):
        a_root = self.find(a)
        b_root = self.find(b)
        if a_root == b_root:
            return
        else:
            if self.size_of(b_root) > self.size_of(a_root): 
                self.parent[a_root] = self.parent[b_root]
                self.size[b_root] += self.size[a_root]
            else:
                self.parent[b_root] = self.parent[a_root]
                self.size[a_root] += self.size[b_root]
                
    def size_of(self,a):
        return self.size[self.find(a)]
    
    def is_same(self,a,b):
        return self.find(a) == self.find(b)


N,M,K = map(int, input().split())
uf = UnionFind(N+1)
friends = []
blocks = [0]*(N+1)
for i in range(N+1):
    blocks.append([])
    friends.append(0)

for i in range(M):
    a,b = map(int, input().split())
    friends[a] += 1
    friends[b] += 1
    uf.unite(a,b)
    

for j in range(K):
    x,y = map(int, input().split())
    if uf.is_same(x,y):
        blocks[x] += 1
        blocks[y] += 1

for i in range(1,N+1):
    print(uf.size_of(i) - friends[i] - blocks[i] -1)

Measured memory_bytes: 17424
class Position
  def initialize(x = 0, y = 0, count = 0)
    @x = x
    @y = y
    @count = count
  end
  attr_reader :x, :y, :count
end

h, w = gets.split.map(&:to_i)
maze = h.times.map {gets.chomp}
field = nil

Position.define_method(:succ) do
  x = @x + 1
  y = @y
  if x >= w
    x = 0
    y += 1
    return false if y >= h
  end
  Position.new(x, y)
end

Position.define_method(:move) do |dir|
  x, y = @x, @y
  dx, dy = [[1, 0], [0, -1], [-1, 0], [0, 1]][dir]
  x += dx
  y += dy
  return false if x >= w || x < 0 || y >= h || y < 0
  return false if field[y][x] != "."
  Position.new(x, y, @count + 1).mark
end

Position.define_method(:mark) do
  field[@y][@x] = "*"
  self
end

solve_maze = ->(start) {
  return 0 if maze[start.y][start.x] == "#"
  field = maze.map(&:dup)
  max = 0
  q = [start.mark]
  while (po = q.shift)
    max = po.count if po.count > max
    4.times do |dir|
      nxt = po.move(dir)
      q << nxt if nxt
    end
  end
  max
}


start = Position.new
max = 0
loop do
  hosuu = solve_maze.(start)
  max = hosuu if hosuu > max
  break unless (start = start.succ)
end

puts max

Measured memory_bytes: 14292
//2013-5

#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <time.h>
#define INF 1e8
#define fs first
#define sc second
#define rep(x,n) for(int x = 0;x < n;x ++)
#define Rep(x,n) for(int x = 1;x <= n;x ++)
using namespace std;


char mp[1005][1005];
int d[1005][1005];
int chx[10];
int chy[10];
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};

//下向きにx,右向きにy
int main(){
    int H,W;
    int N;
    cin >> H >> W;
    cin >> N;
    int ans = 0;
    
    rep(i,H){
        scanf("%s",mp[i]);
        rep(j,W){
            if('1'<=mp[i][j]&&mp[i][j]<'9'){
                chx[mp[i][j]-'0']=i;
                chy[mp[i][j]-'0']=j;
            }else if(mp[i][j]=='S'){
                chx[0]=i;
                chy[0]=j;
            }
        }
    }    rep(i,N){
        queue<pair<int,int> > que;
        rep(j,H){
            rep(k,W){
                d[j][k]=-1;
            }
        }
        d[chx[i]][chy[i]]=0;
        que.push(make_pair(chx[i],chy[i]));
        while(!que.empty()){
            int flag = 0;
            int nowx = que.front().first;
            int nowy = que.front().second;
            que.pop();
            rep(j,4){
                int nextx = nowx+dx[j];
                int nexty = nowy+dy[j];
                if(!(0<=nextx&&nextx<H&&0<=nexty&&nexty<W))
                    continue;
                if( mp[nextx][nexty]!='X' && d[nextx][nexty]==-1){
                    d[nextx][nexty]=d[nowx][nowy]+1;
                    que.push(make_pair(nextx,nexty));
                }
                if(mp[nextx][nexty]=='1'+i){
                    ans += d[nextx][nexty];
                    flag = 1;
                    break;
                }
            }
            if(flag == 1)
                break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6172
use std::io::BufRead;
use std::str::FromStr;
use std::convert::From;

fn main() {
  let stdin = std::io::stdin();
  let mut lines = stdin.lock().lines();

  let dice_v = lines.next().unwrap().unwrap()
    .split_whitespace()
    .map(|x| x.parse::<u32>().unwrap())
    .collect::<Vec<_>>();

  let mut dice = Dice::new(&dice_v);

  for b in lines.next().unwrap().unwrap().as_bytes().iter() {
    dice.roll((*b).into());
  }

  println!("{:?}", dice.top());
}

#[derive(Debug)]
struct Dice {
  data: [u32; 6],
  indices: [usize; 6],
}

impl Dice {
  fn new(xs: &[u32]) -> Self {
    let mut data: [u32; 6] = Default::default();
    data.copy_from_slice(&xs[0..6]);
    Dice { data, indices: [0, 1, 2, 3, 4, 5] }
  }

  fn roll(&mut self, dir: Direction) {
    let s = self.indices;
    self.indices = match dir {
      Direction::N => [s[1], s[5], s[2], s[3], s[0], s[4]],
      Direction::S => [s[4], s[0], s[2], s[3], s[5], s[1]],
      Direction::W => [s[2], s[1], s[5], s[0], s[4], s[3]],
      Direction::E => [s[3], s[1], s[0], s[5], s[4], s[2]]
    }
  }

  fn top(self) -> u32 {
    self.data[self.indices[0]]
  }
}

#[derive(Debug)]
enum Direction {
  N, E, S, W
}

impl FromStr for Direction {
  type Err = String;

  fn from_str(s: &str) -> Result<Self, Self::Err> {
    match s {
      "N" => Ok(Direction::N),
      "E" => Ok(Direction::E),
      "S" => Ok(Direction::S),
      "W" => Ok(Direction::W),
      _   => Err("parse error".into())
    }
  }
}

impl Into<Direction> for u8 {
  fn into(self) -> Direction {
    match self {
      b'N' => Direction::N,
      b'E' => Direction::E,
      b'S' => Direction::S,
      b'W' => Direction::W,
      _    => { panic!("invalid byte"); }
    }
  }
}


Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


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

    int p, q;
    while (cin >> p >> q) {
        int shou[1000], amari[1000];
        int first = -1, last = -1, iscycle = 1;
        for (int i = 0; p != 0; i++) {
            shou[i] = p / q;
            amari[i] = p % q;
            p = amari[i] * 10;
            /*
            dump(shou[i]);
            dump(amari[i]);
            dump(p);
            */
            // ??????????????????????????¢???
            rep(j, i) {
                if(amari[i] == amari[j]) {
                    first = j;
                    last = i;
                    break;
                }
            }
            if (first != -1) break;
            // ?????????????????¨???
            if(amari[i] == 0) {
                last = i;
                iscycle = 0;
                break;
            }
        }

        // 0 = false, other = true
        if (iscycle) {
            rep(i ,last) cout << shou[i + 1];
            cout << endl;
            rep(i ,last) {
                if (i < first) cout << " ";
                else cout << "^"; 
            }
            cout << endl;
        }
        else {
            //dump(last);
            rep(i, last) {
                cout << shou[i + 1];
            }
            cout << endl;
        }


    }



    return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<string>
using namespace std;
int a,b,k;
int main(){
cin >> a >> b >> k;
if(2*k>b-a)
for(int i=a;i<=b;i++)
cout << i << endl;
else{
for(int i=a;i<a+k;i++)
cout << i << endl;
for(int i=b-k+1;i<=b;i++)
cout << i << endl;
}
return 0;
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

  vector<ll> P(N), idx(N);

  rep0(i, N) {
    cin >> P[i];
    P[i]--;
    idx[P[i]] = i;
  }

  set<ll> st;
  ll ans = 0;
  repR0(x, N) {
    ll i = idx[x];
    st.insert(i);

    vector<ll> l(2, -1);
    vector<ll> r(2, N);

    auto itl = st.find(i);
    rep0(j, 2) {
      if (itl == st.begin()) break;
      itl--;
      l[j] = *itl;
    }

    auto itr = st.find(i);
    rep0(j, 2) {
      itr++;
      if (itr == st.end()) break;
      r[j] = *itr;
    }

    ll l1 = i - l[0];
    ll l2 = l[0] - l[1];
    ll r1 = r[0] - i;
    ll r2 = r[1] - r[0];

    ans += (l1 * r2 + l2 * r1) * (x + 1);
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 6528
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
const int INF = 1001001001;
int main(){
  int n;
  cin >> n;
  vector< long long int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  long long ans=0;
  if(n%2==0){
    for(int i=0;i<n/2-1;i++){
      ans=ans+(vec.at(n-1-i)-vec.at(i))*2;
    }
    ans=ans+vec.at(n/2)-vec.at(n/2-1);
  }
  if(n%2!=0){
    for(int i=0;i<n/2;i++){
      ans=ans+(vec.at(n-1-i)-vec.at(i))*2;
    }
    if((vec.at(n/2)-vec.at(n/2-1))<(vec.at(n/2+1)-vec.at(n/2))){
      ans=ans-vec.at(n/2)+vec.at(n/2-1);
    }
    else{
      ans=ans+vec.at(n/2)-vec.at(n/2+1);
    }
  }
  cout << ans << endl;
}
    
            

Measured memory_bytes: 1024
// testcplusplus.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;



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

	vector<int> b;

	for (int i = 0; i < n - 1; i++) {
		int temp;
		cin >> temp;
		b.push_back(temp);
	}

	int sum = b[0];
	int prevMin = sum;

	for (int i = 1; i < n - 1; i++) {
		sum += min(prevMin, b[i]);
		prevMin = b[i];
	}

	sum += b[b.size() - 1];

	cout << sum;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	int n;

	int maxm = 1;
	int cnt = 1;
	for (cin >> n; n--;)
	{
		int a;
		cin >> a;

		if (a == 1)
		{
			cnt++;
		}
		else
		{
			maxm = max(maxm, cnt);
			cnt = 1;
		}
	}

	maxm = max(maxm, cnt);

	cout << maxm << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	int W, H, N; cin >> W >> H >> N;
	vector<int> x(N), y(N), a(N);
	rep(i, 0, N)cin >> x[i] >> y[i] >> a[i];
	int u = H, d = 0, l = 0, r = W;
	rep(i, 0, N) {
		if (a[i] == 1)l = max(x[i], l);
		else if (a[i] == 2)r = min(x[i], r);
		else if (a[i] == 3)d = max(y[i], d);
		else if (a[i] == 4)u = min(y[i], u);
	}
	
	if (u > d&&l < r) {
		int area = (r - l)*(u - d);
		cout << area << endl;
	}
	else cout << 0 << endl;
	

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int[] scores = new int[n];
			for (int i = 0; i < scores.length; i++) {
				scores[i] = sc.nextInt();
			}
			int max = 0, min = 1000, sum = 0;
			for (int i = 0; i < scores.length; i++) {
				sum += scores[i];
				if (scores[i] > max)
					max = scores[i];
				if (scores[i] < min)
					min = scores[i];
			}
			System.out.println((sum - max - min) / (n - 2));
		}
	}
}

Measured memory_bytes: 28784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
ll NUM = pow(10,9)+ 7;

vector<ll> fact, fact_inv;
// 繰り返し二乗法
ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%NUM;
		a=a*a%NUM;
		b>>=1;
	}
	return res;
}
void make_fact(int n){
	fact.resize(n+1);
	fact_inv.resize(n+1);
	fact[0] = fact[1] = 1;
	for(int i(2);i<=n;++i){
		fact[i] = (fact[i-1] * i)%NUM;
	}
	fact_inv[n]=power(fact[n], NUM-2);
    for(int i(n-1);i>=0;--i){
		fact_inv[i]=fact_inv[i+1]*(i+1)%NUM;
	}
}

ll nCr(int n, int r){
	return (fact[n]*fact_inv[r])%NUM*fact_inv[n-r]%NUM;
}


int main(){
	int n,k;
	cin >> n >> k;
	make_fact(n+10);
	int mx = min(k,n-k+1);
	for(int i(1);i<=k;++i){
		if(i<=mx) cout <<  (nCr(n-k+1,i) * nCr(k-1,i-1)) % NUM << endl;
		else cout << 0 << endl;
	}
	return 0;
}

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

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

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

int main() {
	ll ans = (ll)200 * (ll)1000000000;
	ll ans_max = (ll)200 * (ll)1000000000;
	int tmp;
	int t;
	cin >> t;
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>> ,greater<pair<ll, ll>>> q;
	set<ll> s;	
	ll x, y;
	REP(i, t){
		ll n, a, b, c, d;
		cin >> n >> a >> b >> c >> d;
		while(!q.empty()) q.pop();
		s.clear();
		q.push(make_pair(0, n));
		ans = ans_max;
		while(q.top().second != 0){
			x = q.top().first;
			y = q.top().second;
			q.pop();
			if(s.find(y) != s.end()) continue;
			s.insert(y);
			if(y < ans_max / d){
				q.push(make_pair(x+d*y, 0));
			}
			if(y % 2 == 0) q.push(make_pair(x+a, y/2));
			else{
				q.push(make_pair(x+d*(y%2)+a, (y-(y%2))/2));
				q.push(make_pair(x+d*(2-y%2)+a, (y+(2-y%2))/2));
			}
			if(y % 3 == 0) q.push(make_pair(x+b, y/3));
			else{
				q.push(make_pair(x+d*(y%3)+b, (y-(y%3))/3));
				q.push(make_pair(x+d*(3-y%3)+b, (y+(3-y%3))/3));
			}
			if(y % 5 == 0) q.push(make_pair(x+c, y/5));
			else{
				q.push(make_pair(x+d*(y%5)+c, (y-(y%5))/5));
				q.push(make_pair(x+d*(5-y%5)+c, (y+(5-y%5))/5));
			}
		}
		//cout << min(ans, q.top().first + d) << endl;
		cout << q.top().first << endl;
	}
}


Measured memory_bytes: 4092
# 2019-11-15 14:12:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    r = int(sys.stdin.readline().rstrip())
    ans = 3 * r ** 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
using System;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        Console.ReadLine();
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var answer = A.Min(x => { var y = 0; while ((x & 1) == 0) { x >>= 1; y++; } return y;});
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 28160
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int k;cin>>k;
	for (int i=0; i<k; i++)
		if (s[i]!='1'){
			cout<<s[i];
			return 0;
	    }
	cout<<1;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
al = [0] * 26
for _ in range(H):
    a = list(input())
    for i in a:
        al[ord(i) - ord("a")] += 1

two = 0
one = 0
if H % 2 and W % 2:
    two = H + W - 2
    one = 1
elif H % 2:
    two = W 
elif W % 2:
    two = H


for i in al:
    if i % 2:
        one -= 1
        two -= (i % 4) - 1
    else:
        two -= i % 4

if two >= 0 and one == 0 and two % 4 == 0:
    print("Yes")
else:
    print("No")

    

Measured memory_bytes: 3064
import sys


q_size, g_score = map(int, input().split())
q_nums = [0] * q_size
bonus = [0] * q_size
for i in range(0, q_size):
    q_nums[i], bonus[i] = map(int, input().split())


def solve_q(score, q_cnt, q_solved, best_cnt):
    # ボーナスだけでGを突破していたら、そのまま返却する
    if score >= g_score: 
        return min(best_cnt, q_cnt)
    
    # 現状でどの問題が何問残っているかキャッシュし、配点の高い問題から先に解いていく
    q_remained = [0] * q_size
    for i in range(0, q_size):
        q_remained[i] = q_nums[i] - q_solved[i]
        
    for i in range(q_size - 1, -1, -1):
        while q_remained[i] > 0: # Gに達成するまで、あるだけ全部解く
#            print("while in score: ", score)
            score += 100 * (i + 1)
            q_cnt += 1
            q_remained[i] -= 1
            
            if score >= g_score:
                return min(best_cnt, q_cnt)
            
    # ボーナス未反映で、解なしの場合
    return min(best_cnt, q_cnt)

            
best_cnt = sum(q_nums)
# 各Qのボーナスを 使う or 使わない で分岐
for bi in range(0, 2 ** q_size):
    # 初期化
    score = 0
    q_cnt = 0
    q_solved = [0]*q_size

    for pos_i in range(0, q_size):
        if (bi >> pos_i) & 1: # True: ボーナスを使う
            score += 100 * (pos_i + 1) * q_nums[pos_i] + bonus[pos_i]
            q_cnt += q_nums[pos_i]
            q_solved[pos_i] += q_nums[pos_i]
            
    # スコアを引き継いで、得点の高い問題から解いていく
#    print(score, q_cnt, q_solved, best_cnt)
    best_cnt = solve_q(score, q_cnt, q_solved, best_cnt)
    

print(best_cnt)


Measured memory_bytes: 42860
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, K: int, S: str):
    border = []
    prev = False
    first = S[0]
    for i, c in enumerate(S):
        if c != prev:
            border.append(i)
            prev = c
    border.append(N)
    length = len(border)
    if first == '1':
        size = (length - 1) // 2
    else:
        size = length // 2

    if K >= size:
        print(border[-1] - border[0])
        return
    
    res = 0
    for i in range(size-K+1):
        if first == '1': 
            res = max([res, border[min([2*i + 2*K + 1, length-1])] - border[2*i]])
        else: 
            res = max([res, border[min([2*i + 2*K, length-1])] - border[max([2*i - 1, 0])]])
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7412
import java.util.*;

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

        int ans = Integer.MAX_VALUE;
        for(int i = 0; i <= n; i++){
            ans = Math.min(ans, calc(i, 6) + calc(n - i, 9));
        }
        System.out.println(ans);
    }
    public static int calc (int n, int p)
    {
        if(n == 0){
            return 0;
        }
        int i = 1;
        int j = 1;
        while(Math.pow((double) p, (double) i) <= n){
            i++;
            j *= p;
        }
        return 1 + calc(n - j, p);
    }
}

Measured memory_bytes: 21844
while True:
    s = input().split(" ")
    H = int(s[0])
    W = int(s[1])
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H-1:
                print("#",end="")
            else:
                if j == 0 or j == W-1:
                    print("#",end="")
                else:
                    print(".",end="")
        print("")
    print("")

Measured memory_bytes: 8980
#include <stdio.h>

#include <utility>
#include <queue>

using namespace std;

#define INF 1001001

typedef pair<int, int> P;

int main(void){
    queue<P> q;
    P p;
    int i,j,k,h,w,n,dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},ans=0,d[1000][1000];
    char map[1000][1002];
    scanf("%d%d%d",&h,&w,&n);
    for(i=0; i<h; i++){
        scanf("%s",map[i]);
    }
    for(i=0; i<n; i++){
        for(j=0; j<h; j++){
            for(k=0; k<w; k++){
                d[j][k] = INF;
                if(map[j][k]=='S'){
                    q.push(P(j,k));
                    map[j][k]='.';
                    d[j][k] = 0;
                }
            }
        }
        while(!q.empty()){
            p = q.front();
            q.pop();
            if(map[p.first][p.second]=='1'+i){
                ans+=d[p.first][p.second];
                map[p.first][p.second]='S';
                break;
            }
            for(j=0; j<4; j++){
                int nx = p.first + dx[j];
                int ny = p.second + dy[j];
                if(nx>-1 && nx<h && ny>-1 && ny<w && map[nx][ny]!='X' && d[nx][ny]==INF){
                    q.push(P(nx,ny));
                    d[nx][ny]=d[p.first][p.second]+1;
                }
            }
        }
        while(!q.empty()){
            q.pop();
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5936
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
print(a+a**2+a**3)

Measured memory_bytes: 68060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max(max(a*c,a*d), max(b*c,b*d)) << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n;
  const double pi=3.14159265358979323846;
  cin >> n;
  cout << n*2*pi << endl;
}


Measured memory_bytes: 3824
#include <stdio.h>


int main()
{
    int flag=0;
    int n;scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        int tmp;scanf("%d",&tmp);
        if (i!=tmp) flag++;
    }
    if (flag<=2) printf("YES\n");
    else printf("NO\n");

}


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

struct UnionFind {
  vector<int> par;
  vector<int> siz;

  UnionFind(int N) : par(N), siz(N, 1) {
    for ( int i = 0; i < N; i++ ) { par[i] = i; }
  }

  int root(int x) { 
    if ( par[x] == x ) { return x; }
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if ( rx == ry ) { return; }
    if ( siz[rx] < siz[ry] ) { swap(rx, ry); }
    par[ry] = rx;
    siz[rx] += siz[ry];
  }

  int size(int x) {
    return siz[root(x)];
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind tree(n+1);
  for ( int i = 0; i < m; i++ ) {
    int a, b;
    cin >> a >> b;
    tree.unite(a, b);
  }

  int ans = 0;
  for ( int i = 1; i <= n; i++ ) {
    ans = max(ans, tree.size(i));
  }

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


Measured memory_bytes: 4804
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>

using namespace std;

struct Info{
	Info(){
		num = 0;
	}
	char word[26];
	int num;
};

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int strCmp2(char* left,char* right){
	int i;

	if(strCmp(left,right))return 3;

	for(i=0;left[i] != '\0' && right[i] != '\0'; i++){
		if(left[i] != right[i]){
			if(left[i] < right[i])return 1;
			else{
				return 2;
			}
		}
	}
	if(left[i] == '\0')return 1;
	else{
		return 2;
	}
}

void func(int n){

	vector<Info> V[26];

	char buf[2050],work[26],key[2];
	bool Found;

	int index,num_of_each[26],tmp,limit;

	for(int i = 0; i < 26; i++){
		num_of_each[i] = 0;
	}

	for(int i = 0; i < n; i++){
		fgets(buf,2050,stdin);

		index = 0;
		for(int k = 0; buf[k] != '\n' && buf[k] != '\0';k++){
			if(buf[k] == ' '){
				tmp = work[0] - 'a';

				if(num_of_each[tmp] == 0){
					V[tmp].push_back(Info());
					V[tmp][0].num = 1;
					strcpy(V[tmp][0].word,work);
					num_of_each[tmp]++;
				}else{
					Found = false;
					for(int p = 0; p < num_of_each[tmp];p++){

						if(strCmp(work,V[tmp][p].word)){
							V[tmp][p].num++;
							Found = true;
							break;
						}
					}
					if(!Found){
						V[tmp].push_back(Info());
						V[tmp][num_of_each[tmp]].num = 1;
						strcpy(V[tmp][num_of_each[tmp]].word,work);
						num_of_each[tmp]++;
					}
				}
				index = 0;
			}else{
				work[index++] = buf[k];
				work[index] = '\0';

				if(buf[k+1] == '\0' || buf[k+1] == '\n'){

					tmp = work[0] - 'a';

					if(num_of_each[tmp] == 0){
						V[tmp].push_back(Info());
						V[tmp][0].num = 1;
						strcpy(V[tmp][0].word,work);
						num_of_each[tmp]++;
					}else{
						Found = false;
						for(int p = 0; p < num_of_each[tmp];p++){

							if(strCmp(work,V[tmp][p].word)){
								V[tmp][p].num++;
								Found = true;
								break;
							}
						}
						if(!Found){
							V[tmp].push_back(Info());
							V[tmp][num_of_each[tmp]].num = 1;
							strcpy(V[tmp][num_of_each[tmp]].word,work);
							num_of_each[tmp]++;
						}
					}
					index = 0;
				}
			}
		}
	}
	scanf("%s",key);

	tmp = key[0] - 'a';

	limit = num_of_each[tmp];

	for(int i = 1; i <= limit-1; i++){
		for(int k = limit-1; k >= i; k--){
			if(V[tmp][k].num > V[tmp][k-1].num)swap(V[tmp][k],V[tmp][k-1]);
			else if(V[tmp][k].num == V[tmp][k-1].num && strCmp2(V[tmp][k].word,V[tmp][k-1].word) == 1)swap(V[tmp][k],V[tmp][k-1]);
		}
	}

	for(int i = 0; i < min(limit,5); i++){
		if(i == 0)printf("%s",V[tmp][i].word);
		else{
			printf(" %s",V[tmp][i].word);
		}
	}
	if(limit!=0)printf("\n");
	if(limit == 0)printf("NA\n");

}


int main(){

	int n;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;
		getchar();
		func(n);
	}

    return 0;
}

Measured memory_bytes: 3204
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define DAY_MAX	123
#define PASTA_MAX	5
#define ONAZI_MAX	123

int max;


int set_pasta[DAY_MAX];
int memo[DAY_MAX][PASTA_MAX][ONAZI_MAX];

int dp(int day, int pasta, int onazi){
	int numbuf = 0;
	int ans = 0;
	if (memo[day][pasta][onazi] >= 0) return memo[day][pasta][onazi];
	if (onazi == 3) return 0;
	if (day == max - 1) return 1;
	if (set_pasta[day + 1] >= 1){
		if (set_pasta[day + 1] == pasta) return memo[day][pasta][onazi] = dp(day + 1, pasta, onazi + 1);
		else return memo[day][pasta][onazi] = dp(day + 1, set_pasta[day + 1], 1);
	}
	else{
		for (int a = 0; a < 3; a++){
			if (a + 1 == pasta) ans += dp(day + 1, pasta, onazi + 1);
			else ans += dp(day + 1, a + 1, 1);
			ans %= 10000;
		}
		return ans;
	}
}

int main(){
	int num;
	int buf;
	int answer = 0;
	memset(memo, 255, sizeof(memo));
	scanf("%d%d", &max, &num);
	for (int a = 0; a < num; a++){
		scanf("%d", &buf);
		scanf("%d", &set_pasta[buf - 1]);
	}
	if (set_pasta[0] >= 1) printf("%d\n", dp(0, set_pasta[0], 1));
	else printf("%d\n", (dp(0, 1, 1) + dp(0, 2, 1) + dp(0, 3, 1)) % 10000);
	return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	
*/
string s;
void solve()
{
	cout << s[0];
	cout << sz(s) - 2;
	cout << s[sz(s) - 1];
	cout << flush;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> s;

	solve();

	return 0;
}

Measured memory_bytes: 256
N,C,K=map(int, input().split())
l = []
ans = 0
for i in range(N):
    l.append(int(input()))
l.sort()
l.append(float("INF"))
l = l[::-1]
while len(l)>1:
  h=l.pop()
  i=h
  j=1
  while len(l)>1 and j<C and h+K>=l[-1]:
    i=l.pop()
    j+=1
  ans+=1
print(ans)



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


int main()
{
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> wf(n, vector<int>(n, l + 1));
  rep(i, m)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    wf[a][b] = wf[b][a] = c;
  }
  rep(k, n)
    rep(i, n)
      rep(j, n)
        if (wf[i][k] <= l && wf[k][j] <= l)
          wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
  vector<vector<int>> g(n);
  rep(i, n - 1)
    for (int j = i + 1; j < n; j++)
      if (wf[i][j] <= l)
      {
        g[i].push_back(j);
        g[j].push_back(i);
      }
  vector<vector<int>> g2(n, vector<int>(n, -1));
  int query;
  cin >> query;
  rep(i, query)
  {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    queue<pair<int, int>> q;
    q.emplace(s, s);
    while (!q.empty())
    {
      auto p = q.front();
      q.pop();
      int pre = p.first;
      int crt = p.second;
      if (g2[s][crt] != -1)
        continue;
      if (pre != crt)
        g2[s][crt] = g2[s][pre] + 1;
      for (int nxt : g[crt])
        q.emplace(crt, nxt);
    }
    printf("%d\n", g2[s][t]);
    g2[s][s] = 0;
  }
  return 0;
}

Measured memory_bytes: 2556
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll A,B,C;
  cin>>A>>B>>C;
  if(C>A+B&&4*A*B<(C-A-B)*(C-A-B)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;

const int nax = 2e5 + 5;
ll bit[nax];
/// bit on the height of the flowers

void update(ll i, ll upd){
    for(; i < nax; i += i&(-i)) bit[i] = max(bit[i], upd);
}

ll get_max(ll i){
    ll mx = bit[i];
    for(; i > 0; i -= i&(-i)) mx = max(mx, bit[i]);
    return mx;
}


void solve(){
    int n;
    cin>>n;
    vector<ll> h(n), a(n);
    fr(i, n) cin>>h[i];
    fr(i, n) cin>>a[i];

    ll ans = 0ll;
    fr(i, n){
        /// for each element find the max sum with last element as a[i]
        ll mx = get_max(h[i]);
        update(h[i], mx + a[i]);
        ans = max(ans, mx + a[i]);
    }
    cout<<ans;
}

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

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

    return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <list>
#include <vector>
#include <array>
using namespace std;
struct Node{
    Node(int id) : x(0), cnt(0), id(id) {}
    ~Node() = default;
    int x, cnt, id;
    list<Node*> adj;
};
array<bool, 200000> traced {};
void dfs(Node *current, int cnt = 0) {
    traced[current->id] = true;
    current->cnt = cnt + current->x;
    for (auto p : current->adj) {
        if (!traced[p->id]) dfs(p, current->cnt);
    }
}
int main() {
    int N, Q;
    cin >> N >> Q;
    vector<Node*> tree(N);
    for (int i = 0; i < N; i++) tree[i] = new Node(i);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        tree[a-1]->adj.push_back(tree[b-1]);
        tree[b-1]->adj.push_back(tree[a-1]);
    }
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        tree[p-1]->x += x;
    }
    dfs(tree[0]);
    for (auto p : tree) {
        cout << p->cnt << " ";
        delete p;
    }
}

Measured memory_bytes: 32256
#include <iostream>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    for(int i=0;i<n;i++){
        int _a;
        cin >> _a;
        a.push_back(_a);
    }

    sort(a.begin(),a.end());

    int ans=-1;
    for(int i : a){
        i--;
        auto low=lower_bound(a.begin(),a.end(),i-1);
        auto upp=upper_bound(low,a.end(),i+1);
        int count=(upp-low);
        ans=std::max(count,ans);
        i++;
        low=lower_bound(a.begin(),a.end(),i-1);
        upp=upper_bound(low,a.end(),i+1);
        count=(upp-low);
        ans=std::max(count,ans);
        count=std::count_if(a.begin(),a.end(),[i](int x)->bool{return x-1<=i && i<=x+1;});
        i++;
        low=lower_bound(a.begin(),a.end(),i-1);
        upp=upper_bound(low,a.end(),i+1);
        count=(upp-low);
        ans=std::max(count,ans);
    }

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



Measured memory_bytes: 892
import bisect

sosu=set()
nums=[1]*(10**5+1)
for i in range(2, 10**5+1):
  if nums[i]==1:
    sosu.add(i)
    j=i
    while j<10**5+1:
      nums[j]=0
      j+=i
      
nums=[x for x in range(3, 2*10**5+1, 2) if x in sosu and (x+1)//2 in sosu]

Q=int(input())
for _ in range(Q):
  l, r=map(int, input().split())
  a=bisect.bisect_left(nums, l)
  b=bisect.bisect_right(nums, r+1)
  print(b-a)

Measured memory_bytes: 10164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = acos(-1);

int main(){
    long double A, B, H, M;
    cin >> A >> B >> H >> M;

    double h = ( H / 6 + M / 360) * PI;
    double m = M / 30 * PI;
    double l = A * A + B * B - 2 * A * B * cos((double)abs(m - h));
    double ans = sqrt(l);

    cout << setprecision(20) << ans << endl;
    return 0;
}

Measured memory_bytes: 4184
n, k = gets.strip.split(" ").map(&:to_i)

a = 0.0

def c(x, y)
  a = 1
  x *= 2
  while x < y
    a += 1
    x *= 2
  end
  a
end

1.upto(n) do |i|
  if i >= k
    a += 1.0 / n
  else
    if i == 1
      a += 1.0 / (n * 2**(Math.log2(k).ceil))
    else
      a += 1.0 / (n * 2**c(i, k))
    end
  end
end

puts a


Measured memory_bytes: 1916
#include<stdio.h>

void run(void){
  int a,b;
  scanf("%d%d",&a,&b);
  int i;
  for(i=1;i<999;i++){
    if(i*(i+1)/2-a==(i+1)*(i+2)/2-b){
      printf("%d\n",i*(i+1)/2-a);
      return;
    }
  }
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
use std::io::prelude::*;

const N10E9: u64 = 1_000_000_000;

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_to_string(&mut input_str).unwrap();

    let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
    let mut input_parts_it = input_parts.iter().cloned();

    let area: u64 = input_parts_it.next().unwrap().parse().unwrap();
    // area == abs(x1 y2 - x2 y1)

    let x1 = N10E9;
    let y2 = (area + N10E9 - 1) / N10E9;
    let x2 = 1;
    let y1 = x1 * y2 - area;

    println!("0 0 {} {} {} {}", x1, y1, x2, y2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
  double a, b, p;
  cin >> a >> b >> p;
  double h, l, s;

  h = b * sin(p/180 * M_PI);
  l = a + b + sqrt(a*a + b*b - 2*a*b*cos(p/180 * M_PI));
  s = 0.5 * a * h;

  cout << to_string(s) << endl;
  cout << to_string(l) << endl;
  cout << to_string(h) << endl;
  
  return 0;
}


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

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

    double p;

    if(N%2==0){
        p=0.5;
    }else{
        p= (double) (N+1)/2 /N ;
    }

    cout << setprecision(8) << p << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
T,A=list(map(int,input().split()))
H=list(map(int,input().split()))

temp_data=[T-0.006*h for h in H]

output_i=0
for i in range(N):
    if(min(abs(temp_data[i]-A),abs(temp_data[output_i]-A))==abs(temp_data[i]-A)):
        output_i=i
    else:
        continue

print(output_i+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define sortrev(x)       sort(all(x), greater<int>())
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
#define ld               long double
#define endl 			 "\n";
#define mp 				 make_pair
#define pii 			 <int, int>
#define lb 				 lower_bound
#define ub				 upper_bound
#define len(a)           int((a).size())
#define prec(n)          fixed<<setprecision(n)
#define cnt(n)           __builtin_popcountll(n)
#define pi               pair<int, int>
const int mod = 1000000007;
using namespace std;
const int N = 1e9; 
// int n;
// int a[N];



int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >>t;
while(t--){
int n;
cin >>n;
// cout << pow(N,0.2);
for(int i = -2000; i<=2000; i++){
	for(int j = -2000 ; j<=2000; j++){
		// debug(i);
		if(pow(i,5) - pow(j,5) == n){
			// cout << "d";
			cout << i << " " <<j ;
			return 0;
		}
	}
}
// cout <<"D";




}
return 0;
}

Measured memory_bytes: 4156
#include <iostream>
#include <map>

using namespace std;

int main()
{
  long long N, M;
  cin >> N >> M;

  long long A[ N ];
  for( long long i = 0; i < N; ++i )
  {
    cin >> A[ i ];
  }

  long long B[ N + 1 ];
  B[ 0 ] = 0;

  for( long long i = 0; i < N; ++i )
  {
    B[ i + 1 ] = ( B[ i ] + A[ i ] ) % M;
  }

  map<long, long> map;

  for( long long i = 0; i < N + 1; ++i )
  {
    map[ B[ i ] ]++;
  }

  long long ans = 0;
  for( auto entry : map )
  {
    ans += ( entry.second * ( entry.second - 1 ) ) / 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int index = 0;
		while(true) {
			s = s.substring(0, s.length()-1);
			String s1 = s.substring(0, s.length()/2);
			String s2 = s.substring(s.length()/2, s.length());
			if(s1.equals(s2)) {
				index = s1.length() + s2.length();
				break;
			}
		}

		System.out.println(index);

	}
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    vector<ll> S(N+1,0);
    REP(i,N) S[i+1] += S[i] + A[i];//[0,x) [x,y) [y,z) [z,N)に分割
    
    ll ans = 1e15;
    FOR(i,2,N-1){//yは2からN-2で全探索
        int y = i;

        //PQの境界を求める
        int ng = 0;
        int ok = y-1;
        while(abs(ok-ng)>1){
            int mid = (ok+ng)/2;
            if(S[mid] >= S[y]-S[mid]){//ここに条件をかく
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ll x;
        if(abs(S[y]-2*S[ok]) < abs(S[y]-2*S[ng])) x = ok;
        else x = ng;

        //RSの境界も同様に
        ng = y;
        ok = N;
        while(abs(ok-ng)>1){
            int mid = (ok+ng)/2;
            if(S[mid]-S[y] >= S[N]-S[mid]){//ここに条件をかく
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ll z;
        if(abs(S[N]-2*S[ok]+S[y]) < abs(S[N]-2*S[ng]+S[y])) z = ok;
        else z = ng;



        ll max_sum = max({S[x], S[y]-S[x], S[z]-S[y], S[N]-S[z]});
        ll min_sum = min({S[x], S[y]-S[x], S[z]-S[y], S[N]-S[z]});

        ans = min(ans, abs(max_sum - min_sum));
    }

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

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


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

int main() {
ll a[8];
rep(i, 7){
	cin>>a[i];
}

ll ans=0;
ans+=a[2];

ll cnt=0;
  if(a[1]%2==1){cnt++;}
  if(a[4]%2==1){cnt++;}  
  if(a[5]%2==1){cnt++;}

  if(cnt==3||cnt==0){ans+=a[1]+a[4]+a[5];}
 
  else if(cnt==1){ans+=a[1]+a[4]+a[5]-1;}
  else if(cnt==2 && a[1]!=0 && a[4]!=0 && a[5]!=0){
    ans+=a[1]+a[4]+a[5]-1;}
  else{ans+=a[1]+a[4]+a[5]-2;}
  
  
cout<<ans<<endl;
return 0;
}




Measured memory_bytes: 256
n = int(input())
T,a = map(int,input().split())
h = [int(i) for i in input().split()]
mn = 10**9
for i in range(n):
    mn_kouho = abs(a-(T-h[i]*0.006))
    if mn > mn_kouho:
        mn = mn_kouho
        ans = i+1
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define NIL -(long long)(1e9)
#define ll long long
// long long n,w;
bool dp[100005]={0};	//true if cur player wins
long long datas[3005];
int n,k;








int main () {
//memset(dp,-1,sizeof(dp));
// freopen("a.in","r",stdin);  freopen("a.out","w",stdout);
cin>>n>>k;

double d1;
		
for (int i = 0; i < n; ++i)
{
	cin>>datas[i];		
}
for (int i = 1; i <= k; ++i)
{	for(int tas: datas)
	{if(tas==0) break;
	if (tas<=i && !dp[i-tas]) // 0 1 0
		{dp[i]=true;}	}	

}
//for(bool k: dp)
cout<<(dp[k]?"First":"Second");
	return 0;
}



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

A = [a for a in input()]

B = [b for b in input()]

C = [c for c in input()]

count = 0

for i in range(N):
	if ( A[i] == B[i] and A[i] != C[i] ) \
	or ( B[i] == C[i] and B[i] != A[i] ) \
	or ( C[i] == A[i] and C[i] != B[i] ):
		count += 1
	if  A[i] != B[i] \
	and B[i] != C[i] \
	and C[i] != A[i]:
		count += 2

print(count)




Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define ed "\n";
bool judge(int n,map<int,int>& D){
    while(n){
        if(D[n%10]) return false;
        n/=10;
    }
    return true;
}
int main(){
    int n,k;
    cin >> n >> k;
    map<int,int> D={{0,0},{1,0},{2,0},{3,0},{4,0},{5,0},{6,0},{7,0},{8,0},{9,0}};
    for(int i=0; i<k; i++){
        int a;
        cin >> a;
        D[a]= 1;
    }
    while(1){
        if(judge(n,D)) break;
        n++;
    }
    cout << n << ed;
}

Measured memory_bytes: 760