akhauriyash/Code-Regression huggingface dataset:
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

const MOD: usize = 1000000007;

fn main() {
   input! {
      n: usize,
      xy: [(usize, usize); n - 1]
   }
   let mut to = vec![vec![]; n];
   for (x, y) in xy {
      to[x - 1].push(y - 1);
      to[y - 1].push(x - 1);
   }

   let mut dp = vec![vec![1; 2]; n];
   rec(0, 0, &to, &mut dp);
   println!("{}", (dp[0][0] + dp[0][1]) % MOD);
}

fn rec(v: usize, p: usize, to: &Vec<Vec<usize>>, dp: &mut Vec<Vec<usize>>) {
   for &u in to[v].iter() {
      if u == p {
         continue;
      }
      rec(u, v, to, dp);
   }
   if v != 0 {
      dp[p][0] *= dp[v][0] + dp[v][1];
      dp[p][1] *= dp[v][0];
      dp[p][0] %= MOD;
      dp[p][1] %= MOD;
   }
}


Measured memory_bytes: 22140
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    FOR(i,1,4){
        if((a*b*i)%2){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int nummer(char x){
  if(x=='A') return 1;
  return 2;
}
int main(){
  string s;
  string t;
  cin>>s>>t;
  vector<int> sums(s.size()+1);
  sums[0]=0;
  for(int i=1;i<=s.size();i++){
    sums[i]=sums[i-1]+nummer(s[i-1]);
  }
  vector<int> sumt(t.size()+1);
  sumt[0]=0;
  for(int i=1;i<=t.size();i++){
    sumt[i]=sumt[i-1]+nummer(t[i-1]);
  }

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--,b--,c--,d--;
    if((sums[b+1]-sums[a])%3==(sumt[d+1]-sumt[c])%3){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }

  }
  
  return 0;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  bool flag = false;
  int num = 0;

  string s; cin >> s;

  if (s[0] == '9' || s[1] == '9') flag = true;

  // cout << num << endl;
  cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
n,a,b= map(int, input().split())
total = 0
for i in range(1,n+1):
  sums = 0
  x = i
  while(True):
    sums += x%10
    x = x//10
    if x==0:
      break
  if sums >=a and sums <= b:
    total += i
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vll;
     
int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  bool ok = (sz(s) % 2 == 0);
  for (int i = 0; i < sz(s); i += 2) {
    ok &= (s[i] == 'h' and s[i + 1] == 'i');
  }
  if (ok) cout << "Yes\n";
  else cout << "No\n";
  return (0);
}


Measured memory_bytes: 256
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

int d[10];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//
	for (int i = 0; i < 3; i++) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		d[x]++;
		d[y]++;
	}
	sort(d, d + 4);
	if (d[0] == 1 && d[1] == 1 && d[2] == 2 && d[3] == 2)
		cout << "YES\n";
	else
		cout << "NO\n";
	//
	//
}



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

using namespace std;
using ll = long long;

int main(void)
{
    string s;
    int    wcnt = 0;
    ll     ans  = 0;
    cin >> s;

    for (int i = (int)s.size() - 1; i >= 0; --i)
    {
        if (s[i] == 'W')
            ++wcnt;
        else
            ans += wcnt;
    }

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


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b; cin>>n>>a>>b;
    int ans=0;
    FOR(i,1,n){
        string s = to_string(i);
        ll sum=0;
        rep(j,s.size()){
            sum+=s[j]-'0';
        }
        if (a<=sum && sum<=b) ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int N,t[100010],x[100010],y[100010];
int main(){
  cin >> N;
  t[0]=x[0]=y[0]=0;
  int md,td;
  rep(i,N){
    cin >> t[i+1] >> x[i+1] >> y[i+1];
    td = t[i+1]-t[i];
    md = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(td>=md && td%2==md%2){
      //ok
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_N 55555

int prime[MAX_N];//i番目の素数
bool is_prime[MAX_N + 1];//is_prime[i]がtrueならiは素数

//n以下の素数の数を返す
int eratos(int n){
    int p = 0;
    for(int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

signed main(){
    int n;
    cin >> n;
    eratos(MAX_N);
    int cnt = 0;
    for(int i = 6; i <= MAX_N; i += 5){
        if(is_prime[i] == true){
            cout << i << endl;
            cnt++;
            if(cnt >= n){
                break;
            }
        }
    }
    return 0;
}

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

using namespace std;

constexpr double EPS = 1e-10;

struct Point {
    double x, y;

    Point() {}
    Point(double x, double y) : x{x}, y{y} {}

    Point operator - (const Point& p) const
    {
        return Point(x - p.x, y - p.y);
    }
};

double dot(const Point& a, const Point& b)
{
    return a.x * b.x + a.y * b.y;
}

double cross(const Point& a, const Point& b)
{
    return a.x * b.y - b.x * a.y;
}

double norm(const Point& p)
{
    return dot(p, p);
}

double abs(const Point& p)
{
    return sqrt(norm(p));
}

constexpr int COUNTER_CLOCKWISE = +1;
constexpr int CLOCKWISE         = -1;
constexpr int ONLINE_BACK       = +2;
constexpr int ONLINE_FRONT      = -2;
constexpr int ON_SEGMENT        = +0;
using Vector = Point;

int ccw(const Point& p0, const Point& p1, const Point& p2)
{
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if (cross(a, b) > EPS)  return COUNTER_CLOCKWISE;
    if (cross(a, b) < -EPS) return CLOCKWISE;
    if (dot(a, b) < -EPS)   return ONLINE_BACK;
    if (norm(a) < norm(b))  return ONLINE_FRONT;
    return ON_SEGMENT;
}

using Polygon = vector<Point>;

bool sortY(Point p1, Point p2)
{
    if (p1.y != p2.y) {
        return (p1.y - p2.y < -EPS);
    } else { 
        return (p1.x - p2.x < -EPS);
    }
}

Polygon convex_hull(Polygon &ps)
{
    int N = ps.size(), j = 0;
    Polygon pg(N * 2);
    sort(ps.begin(), ps.end(), sortY);
    for (int i = 0; i < N; i++) {
        while (j > 1 && cross(pg[j - 1] - pg[j - 2], ps[i] - pg[j - 1]) <= 0) {
            j--;
        }
        pg[j++] = ps[i];
    }
    int k = j;
    for (int i = N - 2; i >= 0; i--) {
        while (j > k && cross(pg[j - 1] - pg[j - 2], ps[i] - pg[j - 1]) <= 0) {
            j--;
        }
        pg[j++] = ps[i];
    }
    pg.resize(j - 1);
    return pg;
}

double area(const Polygon& pg)
{
    int N = pg.size();
    double res = 0;
    for (int i = 0; i < N; i++) {
        res += cross(pg[i], pg[(i + 1) % N]);
    }
    return abs(res) / 2.0;
}

bool pass_snake(const vector<Point>& ps)
{
    int N = ps.size();
    Polygon p;
    double curr = 0, prev = 0;
    
    for (int i = 0; i < N; i++) {
        p.emplace_back(ps[i]);
        
        if (i >= 2) {            
            p = convex_hull(p);
            curr = area(p);

            if (abs(curr - prev) < EPS) {
                return 0;
            }
        
            prev = curr;
        }
    }
    
    return 1;
}

int main()
{
    int N;
    cin >> N;
    vector<Point> ps(N);
    for (int i = 0; i < N; i++) {
        cin >> ps[i].x >> ps[i].y;
    }
    
    bool poss = 1;
    for (int i = 0; i < 2; i++) {
        poss &= pass_snake(ps);
        reverse(ps.begin(), ps.end());
    }

    cout << (poss ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 3348
n = input()
a = input().split()
an = 0

while True:
    c = 0
    for i in range(int(n)):
        if int(a[i]) % 2 == 0:
            c += 1
    if c == int(n):
        an += 1
        for i in range(int(n)):
            a[i] = int(a[i]) / 2
    else:
        break
            
print(an)
        

Measured memory_bytes: 3060
/**
 *    author:  tourist
 *    created: 09.08.2020 15:48:46       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  const int MAX = 60;
  vector<vector<int>> cnt(MAX, vector<int>(MAX));
  for (int i = 0; i < n; i++) {
    long double x;
    cin >> x;
    long long y = (long long) (x * 1e9 + 0.5);
    int a = 0, b = 0;
    while (y % 2 == 0) {
      y /= 2;
      a += 1;
    }
    while (y % 5 == 0) {
      y /= 5;
      b += 1;
    }
    cnt[a][b] += 1;
  }
  long long ans = 0;
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++) {
      for (int ii = 0; ii < MAX; ii++) {
        for (int jj = 0; jj < MAX; jj++) {
          if (make_pair(i, j) <= make_pair(ii, jj)) {
            if (i + ii >= 18 && j + jj >= 18) {
              if (i == ii && j == jj) {
                ans += (long long) cnt[i][j] * (cnt[i][j] - 1) / 2;
              } else {
                ans += (long long) cnt[i][j] * cnt[ii][jj];
              }
            }
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
typedef long long int ll;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    enter
    ll n, ans;   cin>>n;
  	if(n%1000 == 0)
      ans = 0;
  	else
      ans = 1000 - n%1000;
    cout<<ans;
    return 0;
}

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

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

    vector<vector<long long>> T(3*N, vector<long long>(6*N+1));
    T[0][3*N+1] = 1;
    T[1][3*N-1] = 1;
    T[2][3*N] = 2;
    for (int i=0; i<3*N; i++)
        for (int j=0; j<=6*N; j++)
            if (T[i][j]>0)
                for (int k=1; k<=3; k++)
                    if (i+k<3*N)
                    {
                        long long c = 1;
                        for (int l=0; l<k-1; l++)
                            c *= i+l+2;
                        int d = int(k==1) - int(k==2);
                        T[i+k][j+d] += c*T[i][j];
                        T[i+k][j+d] %= M;
                    }
    long long ans = 0;
    for (int i=3*N; i<=6*N; i++)
    {
        ans += T[3*N-1][i];
        ans %= M;
    }
    cout<<ans<<endl;
}


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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct UnionFind {
private:
    vector<int> par,depth;
public:
    UnionFind (int n) {
        par.resize(n);
        depth = vector<int>(n,0);
        for (int i = 0;i < n;++i) par[i] = i;
    }

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

    void unite(int x,int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (depth[x] < depth[y]) par[x] = y;
        else {
            par[y] = x;
            if (depth[x] == depth[y]) depth[x]++;
        }
    }

    bool same(int x,int y) {
        return find(x) == find(y);
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    UnionFind a(n);
    for (int i = 0;i < q;++i) {
        int c,x,y;
        cin >> c >> x >> y;
        if (c) cout << a.same(x,y) << endl;
        else a.unite(x,y);
    }
    return 0;
}


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

int main() {

	ll n, x; cin >> n >> x;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	if (x < a[0]) {
		ans += a[0] - x;
		a[0] = x;		
	}
	for (int i = 1; i < n; i++) {
		ll a_next = a[i];
		ll a_now = a[i - 1];
		if (a_now + a_next < x) {}
		else { // x <= a_now + a_next 
			ll diff = a_now + a_next - x;
			a[i] -= diff;
			ans += diff;
		}		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4020
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

bool is_even(char *s, int len){
	bool ret = true;
	
	for(int i=0;i<len/2;i++){
		if(*(s+i) != *(s+i+len/2)){
			ret = false;
		}
	}
	
	return ret;
}

int main(void) {
	
	char string[200];
	scanf("%s", string);
	
	int i = strlen(string) - 2;
	while(!is_even(string,i)) i -= 2;
	
	printf("%d",i);
	
	return 0;
}


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

int main(){
  int x; cin>>x;
  for (int i=-200; i<200; i++){
    for (int j=-200; j<200; j++){
      if (pow(i,5)-pow(j,5)==x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4080
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var ans = 3 * Math.Pow(IO.GetInt(), 2);

            Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

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

int main() {
  int a,b,q;
  cin >> a>> b>> q;
  vl s(a),t(b);
  rep(i,a)cin >> s[i];
  rep(i,b)cin >> t[i];
  s.push_back(100100100100100);
  t.push_back(100100100100100);
  s.push_back(-100100100100100);
  t.push_back(-100100100100100);
  sort(rng(s));
  sort(rng(t));
  vl ds(a+2),dt(b+2);
  a+=2;b+=2;
  rep(i,a){
    int x = lower_bound(rng(t),s[i])-t.begin()-1;
    //f(x>0)if(abs(s[i] - t[x])>abs(s[i]-t[x-1])) x--;
    int y = upper_bound(rng(t),s[i])-t.begin();
    ds[i] = min(abs(s[i]-t[x]),abs(s[i]-t[y]));
    //cout<<s[i]<<":"<<ds[i]<<endl;
  }
  rep(i,b){
    int x = lower_bound(rng(s),t[i])-s.begin()-1;
    //if(x>0)if(abs(t[i] - s[x])>abs(t[i]-s[x-1])) x--;
    int y = upper_bound(rng(s),t[i])-s.begin();
    dt[i] = min(abs(t[i]-s[x]),abs(t[i]-s[y]));
    //cout<<t[i]<<":"<<dt[i]<<endl;
  }
  vl ans;
  rep(i,q){
    ll c;
    cin >> c;
    ll cost = 0;
    int x = lower_bound(rng(t),c)-t.begin()-1;
    int y = upper_bound(rng(t),c)-t.begin();
    //if(x>0)if(abs(c - t[x])>abs(c-t[x-1])) x--;
    cost = min(abs(c-t[x])+dt[x],abs(c-t[y])+dt[y]);

    x = lower_bound(rng(s),c)-s.begin()-1;
    y = upper_bound(rng(s),c)-s.begin();
    //if(x>0)if(abs(c - s[x])>abs(c-s[x-1])) x--;
    cost = min(cost,min(abs(c-s[x])+ds[x],abs(c-s[y])+ds[y]));

    ans.push_back(cost);
  }
  for(auto e : ans) print(e);
  return 0;
}

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

array<ll, 51> LayerP;
array<ll, 51> LayerB;

ll bfs(ll layer, ll X)
{
    if (layer == 0) {
        // LV0バーガーはパティ1枚(LV1で再帰せずに処理されるはずなので、多分なくても良い)
        return 1;
    }

    // 最初のバン
    ll paty = 0;
    X--;
    if (X == 0) {
        return paty;
    }

    // 一つ下位レベルのバーガー
    if (X >= LayerP[layer - 1] + LayerB[layer - 1]) {
        paty += LayerP[layer - 1];
        X -= LayerP[layer - 1] + LayerB[layer - 1];
    } else {
        return paty + bfs(layer - 1, X);
    }
    if (X == 0) {
        return paty;
    }

    // 中央のパティ
    paty++;
    X--;
    if (X == 0) {
        return paty;
    }

    // 一つ下位のレベルのバーガー
    if (X >= LayerP[layer - 1] + LayerB[layer - 1]) {
        paty += LayerP[layer - 1];
        X -= LayerP[layer - 1] + LayerB[layer - 1];
    } else {
        return paty + bfs(layer - 1, X);
    }
    if (X == 0) {
        return paty;
    }

    // 最後のバン
    X--;
    return paty;
}

void main_()
{
    LayerP[0] = 1;
    LayerB[0] = 0;
    for (ll i = 1; i <= 50; ++i) {
        LayerP[i] = LayerP[i - 1] * 2 + 1;
        LayerB[i] = LayerB[i - 1] * 2 + 2;
    }

    ll N, X;
    cin >> N >> X;

    cout << bfs(N, X) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

#define ll long long int

using namespace std;

int main() {
    vector<ll> A(3);

    for (auto & a : A) cin >> a;
    ll n;
    cin >> n;

    ll ma = max(A[0], max(A[1], A[2]));
    ll res = A[0] + A[1] + A[2] - ma;
    res += ma << n;
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

int gcd(int x, int y) {
   if(x < y) swap(x, y);
   if(x % y == 0) return y;
   else return gcd(y, x % y);
}
bool check(int a, int b, int c, int d) {
   if (b > d) return false;
   int n = (a - c - 1) / gcd(b,d);
   return a - gcd(b,d) * max(0LL, n) >= b;
}

signed main()
{
   int T; cin >> T;
   V<int> a(T), b(T), c(T), d(T);
   REP(i, T) {
      cin >> a[i] >> b[i] >> c[i] >> d[i];
   }
   REP(i, T) {
      cout << (check(a[i],b[i],c[i],d[i]) ? "Yes" : "No") << endl;
   }

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int x,i=2,j,flag=0;
  cin>>x;
  if(x==2);
  else if(x==3||x==5)i=x;
  else {
    if(x%2==0)
     x++;
     for(i=x;i;i+=2){
       for(j=3;j<=(int)sqrt(i);j+=2){
         if(i%j==0)
         flag++;
       }
       if(flag==0)
      break;
    else
      flag=0;
     }
    
  }
  cout<<i;
  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>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

signed main() {
	int n, k;
	string s;
	
	cin >> n >> k >> s;
	k--;
	if (s[k] == 'A') s[k] = 'a';
	if (s[k] == 'B') s[k] = 'b';
	if (s[k] == 'C') s[k] = 'c';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll n;
ll A[N+5];
ll B[N+5];

int main()
{
  finp;
  cin>>n;
  afor(i,1,n)cin>>A[i]>>B[i];
  ll curr = 0;
  bfor(i,n,1)
  {
    A[i]+=curr;
    ll rem = A[i]%B[i];
    if(rem > 0)
    {
      curr+= B[i] - rem;
      A[i]+= B[i] - rem;
    }
    assert(A[i] % B[i] == 0);
  }

  cout<<curr;
  
return 0;
}

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int W = in.nextInt();
            int H = in.nextInt();
            int N = in.nextInt();
            int x1 = 0, x2 = W, y1 = 0, y2 = H;
            for (int i = 0; i < N; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                int a = in.nextInt();
                if (a == 1) {
                    x1 = Math.max(x1, x);
                } else if (a == 2) {
                    x2 = Math.min(x2, x);
                } else if (a == 3) {
                    y1 = Math.max(y1, y);
                } else if (a == 4) {
                    y2 = Math.min(y2, y);
                }
            }
            if (x2 <= x1 || y2 <= y1) {
                out.println(0);
            } else {
                out.println((x2 - x1) * (y2 - y1));
            }
        }

    }
}



Measured memory_bytes: 22100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();


		long num1 = a * c;
		long num2 = a * d;
		long num3 = b * c;
		long num4 = b * d;

		long result = num1;

		if (result <= num2) {
			result = num2;
		}
		if (result <= num3) {
			result = num3;
		}
		if (result <= num4) {
			result = num4;
		}



		//結果出力
		System.out.println(result);
	}
}

Measured memory_bytes: 35712
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    cnt = 0
    for i in range(3, a+1):
        for j in range(2, i):
            for k in range(1, j):
                if i+j+k == b:
                    cnt += 1
    print (cnt)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}

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

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

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;cin>>h>>w;
    char C[h+2][w+2];
    string s;
    for(int i=0;i<h+2;i++){
        if(i>0&&i<h+1)cin>>s;
        for(int j=0;j<w+2;j++){
            if(i==0||i==h+1)C[i][j]='.';
            else if(j==0||j==w+1)C[i][j]='.';
            else C[i][j]=s[j-1];
        }
    }
    int count=0;
    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            if(C[i][j]=='.'){
            if(C[i-1][j-1]=='#')count++;
            if(C[i-1][j]=='#')count++;
            if(C[i-1][j+1]=='#')count++;
            if(C[i][j-1]=='#')count++;
            if(C[i][j+1]=='#')count++;
            if(C[i+1][j-1]=='#')count++;
            if(C[i+1][j]=='#')count++;
            if(C[i+1][j+1]=='#')count++;
            if(count==0)C[i][j]='0';
            if(count==1)C[i][j]='1';
            if(count==2)C[i][j]='2';
            if(count==3)C[i][j]='3';
            if(count==4)C[i][j]='4';
            if(count==5)C[i][j]='5';
            if(count==6)C[i][j]='6';
            if(count==7)C[i][j]='7';
            if(count==8)C[i][j]='8';
            }
            if(j==w)cout<<C[i][j]<<endl;
            else cout<<C[i][j];
            count=0;
        }
    }
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
namespace fastio{
	template<typename tn> void read(tn &a){
	    tn x=0,f=1;char c=' ';
	    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
	    a=x*f;
	}
	template<typename tn> void print(tn a){
	    if(a<0) putchar('-'),a=-a;
	    if(a>9) print(a/10);
	    putchar(a%10+'0');
	}
};
using namespace fastio;
int n,k,d,ans;
bool b[105];
int main(){
	read(n);
	read(k);
	for(int i=1;i<=k;i++){
		read(d);
		while(d--){
			int a;
			read(a);
			if(!b[a]) ans++;
			b[a]=1;
		}
	}
	printf("%d\n",n-ans);
	return 0;
}

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

int main()
{
    long long a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    long long ans = 0;

    if (a + b <= c*2)
    {
        ans = a * x + b * y;
    }else
    {
        if (x>=y)
        {
            ans += 2*c * y;
            if (a > 2*c)
            {
                ans += c * (x-y) *2;
            }else
            {
                ans += a * (x-y);
            }
            
            
        }else
        {
            ans += 2*c * x;
            if (b > 2*c)
            {
                ans += c * (y-x) *2;
            }else
            {
                ans += b * (y-x);
            }
        }
        
        
    }

    cout << ans << endl;
    
    
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int A = Integer.parseInt(strArr[0]);
		int B = Integer.parseInt(strArr[1]);
		int ans = 0;
		for (int i = A; i <= B; i++) {
			String s = Integer.toString(i);
			ans++;
			for (int j = 0; j < s.length(); j++) {
				if (s.charAt(j) != s.charAt(s.length() - j - 1)) {
					ans--;
					break;
				}
			}
		}
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {
	}
}


Measured memory_bytes: 25428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz=1e5+5;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = 0;
    if((a-b)%2) ans += min(min(a,b)-1, n-max(a,b)) + 1;
    ans += abs(a-b)>>1;

    cout << ans << endl;
}


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

int main() {
  string a, b, c; cin >> a >> b >> c;
  if(a[a.length()-1] == b[0]) {
    if(b[b.length()-1] == c[0]){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++)
    {
        int j = x - i;
        if(i * 4 + j * 2 == y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

void moveE(int dice[]);
void moveN(int dice[]);
void moveS(int dice[]);
void moveW(int dice[]);

int main(void)
{	
	int dice[6];
	for (int i = 0; i < 6; i++) cin >> dice[i];
	
	char order[101] = "\0";
	cin >> order;
	
	for (int j = 0; order[j] != '\0'; j++) {
		if (order[j] == 'E') moveE(dice);
		else if (order[j] == 'N') moveN(dice);
		else if (order[j] == 'S') moveS(dice);
		else moveW(dice);
	}
	
	cout << dice[0] << endl;
	
	return 0;
}

void moveE(int dice[])
{
	int temp = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = temp;
}

void moveN(int dice[])
{
	int temp = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = dice[4];
	dice[4] = temp;
}

void moveS(int dice[])
{
	int temp = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = temp;
}

void moveW(int dice[])
{
	int temp = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = dice[3];
	dice[3] = temp;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

typedef long long ll;
typedef pair<int,int> p;

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

#define MAX_N 100000
int N;
ll A[MAX_N];
ll sumA[MAX_N+1];
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    sort(A, A+N);
    REP(i, N) {
        sumA[i+1] = sumA[i] + A[i];
    }
    REP(i,N) {
        ll n = sumA[i+1];
        while(true) {
            auto it = upper_bound(A,A+N,n*2);
            ll idx = it - A;
            idx--;
            // 変化なし
            if (sumA[idx+1] == n) {
                break;
            }
            // 生き残れる
            else if (idx+1 == N) {
                cout <<  N - i << endl;
                return 0;
            }
            // その他
            else {
                n = sumA[idx+1];
            }
        }
    }
    return 0;
}

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


typedef unsigned long long int ull;

int main() {
    ull h;
    cin >> h;
    ull atk=0,num=1;
    //cout << h << endl;
    while(h>1) {
        h/=2;
        num*=2;
        atk+=num;
    }
    atk++;
    cout << atk << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
const int V = 60;
int n;
vector<int> sche[31];
set<int> have[V];

int solve(){
  for(int i=0;i<n;++i) have[i].insert(i);
  for(int i=1;i<=30;++i){
    for(int j=0;j<sche[i].size();++j)
      for(int k=0;k<sche[i].size();++k)
	for(set<int>::iterator it = have[sche[i][k]].begin(); it!=have[sche[i][k]].end();++it)
	  have[sche[i][j]].insert(*it);
    for(int j=0;j<n;++j)
      if(have[j].size()==n) return i;
  }
  return -1;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;++i) have[i].clear();
    for(int i=0;i<=30;++i) sche[i].clear();
    for(int i=0;i<n;++i){
      int a; cin >> a;
      while(a--){
	int d;cin >> d;
	sche[d].push_back(i);
      }
    }
    cout << solve() << endl;
  }
  
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    ll n,k; cin >> n >> k;
    vector<double> p(n);
    rep(i, n) cin >> p[i];

    ll left = 0;
    ll right = k-1;
    double now = 0.0;
    rep(i, k) {
        now += ((p[i]*(p[i]+1))/2)/p[i];
    }
    double ans = now;
    while(true) {
        now -= ((p[left]*(p[left]+1))/2)/p[left];
        left++;
        right++;
        if(right >= n) break;
        now += ((p[right]*(p[right]+1))/2)/p[right];
        chmax(ans, now);
    }

    cout << setprecision(7) << ans << endl;


    return 0;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main(){

  while(1){
    int in;
    cin >> in;
    if(in == 0) break;

    int money = 1000;
    money -= in;

    int sum = 0;

    if(money >= 500){
      sum++;
      money -= 500;
    }

    while(money >= 100){
      sum++;
      money -= 100;
    }

    if(money >= 50){
      sum++;
      money -= 50;
    }

    while(money >= 10){
      sum++;
      money -= 10;
    }

    if(money >= 5){
      sum++;
      money -= 5;
    }

    sum += money;

    cout << sum << endl;

  }

  return 0;
}

Measured memory_bytes: 0
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N = 1000000, X, ans;
    cin >> X;
    bool prime[N+1];
    fill_n(prime, N+1, true);
    rep2(i, 2, N){
        if(prime[i]){
            if(i >= X){ans = i; break;}
            int j = 2;
            while(j*i <= N){
                prime[j*i] = false;
                j++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    ans0 = 0
    for i in range(len(S)):
        if i % 2 == 0 and S[i] != '0':
            ans0 += 1
        if i % 2 == 1 and S[i] != '1':
            ans0 += 1
    ans1 = 0
    for i in range(len(S)):
        if i % 2 == 0 and S[i] != '1':
            ans1 += 1
        if i % 2 == 1 and S[i] != '0':
            ans1 += 1
    return min(ans1, ans0)


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6084
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int a = sc.nextInt();
			if(n==0 && m==0 && a==0)break;
			
			int[][] map = new int[1001][n+1];
			int b, c, d;
			for(int i=0;i<m;i++){
				b = sc.nextInt();
				c = sc.nextInt();
				d = sc.nextInt();
				map[b][c] = d;
				map[b][d] = c;
			}
			
			for(int i=1000;i>0;i--){
				if(map[i][a]!=0)a=map[i][a];
			}
			System.out.println(a);
			
		}
	
	}	
}

Measured memory_bytes: 70768
N,M,X = map(int,input().split())
B=[0]*N
for i in range(N):
    B[i]=list(map(int, input().strip().split()))

x=N*10**10
sum_ok = N*10**10
unst =[0]*M
flg=0

def all0(v):
    return 0


for i in range(2**N):
    # print(bin(i))
    sum = 0
    unst = list(map(all0,unst))
    for j in range(N):
        if (i >> j) & 1 :
            # print(j)
            sum += B[j][0]
            # unst = list(map(lamda:x,x+B[j][]))
            for k in range(M):
                unst[k]+=B[j][k+1]
    # print(unst)
    # print("sum=",sum)
    if all(elem >= X for elem in unst):
        sum_ok = sum
        flg=1
    x=min(x,sum_ok)
    # print(x)
        
# print(unst)

if flg==0:
    print(-1)
else:
    print(x)
        
        
        

Measured memory_bytes: 9172
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.Scanner;

import javax.swing.plaf.synth.SynthSeparatorUI;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int ans = 0;
		
		for(int i = 1; i * 2 + 1 <= N; i++){
			int n = i * 2 + 1;
			int count = 0;
			for(int j = 1; j * 2 + 1 <= n; j++){
				if(n % (j * 2 + 1) == 0) count++;
				if(count > 7) break;
			}
			if(count == 7) ans++;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 22228
#include <stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int r[n],l[n],ans = 0;
  for(int i = 0;i < n;i++){
    scanf("%d %d",&r[i],&l[i]);
    ans += (l[i] - r[i] + 1);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc042/tasks/abc042_a

#include <stdio.h>
#define forn(i,L,R) for (int i = L; i < R; i++)
#define ll long long
#define wez(n) int (n); scanf("%d",&(n))
#define getString(x) scanf("%s", x)
#define getInt(a) scanf("%d", &a)
#define swap(x,y) { x = x + y; y = x - y; x = x - y; }

int main(){
    wez(a);
    wez(b);
    wez(c);
    if (a > b)
        swap(a, b);
    if (b > c)
        swap(b, c);
    if (a > b)
        swap(a, b);
    if (a == 5 && b == 5 && c == 7)
        printf("YES\n");
    else
        printf("NO\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

class Mint {
public:
  typedef long long val_type;

  Mint(val_type x=0, int m=MOD) : val((x%m+m)%m), mod(m) {}
  val_type value() const { return val; }
  Mint& operator+=(const Mint a) {
    if ((val += a.val) >= mod) val -= mod;
    return *this;
  }
  Mint& operator-=(const Mint a) {
    if ((val += mod-a.val) >= mod) val -= mod;
    return *this;
  }
  Mint& operator*=(const Mint a) {
    (val *= a.val) %= mod;
    return *this;
  }
  Mint operator+(const Mint a) const {
    Mint res(*this);
    return res+=a;
  }
  Mint operator-(const Mint a) const {
    Mint res(*this);
    return res-=a;
  }
  Mint operator*(const Mint a) const {
    Mint res(*this);
    return res*=a;
  }
  Mint pow(val_type t) const {
    if (!t) return 1;
    Mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  Mint inv() const {
    return pow(mod-2);
  }
  Mint& operator/=(const Mint a) {
    return (*this) *= a.inv();
  }
  Mint operator/(const Mint a) const {
    Mint res(*this);
    return res/=a;
  }

private:
  val_type val;
  int mod;
};

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

    int N, K;
    cin >> N >> K;

    Mint ans(0);
    vector<Mint> divCount(K+1);    //! divCount[x] => The count of numbers that can be divided by x but not by 2x, 3x, ... within [1..K] range
    for (int x = K; 1 <= x; --x) {
        divCount[x] = Mint(K/x).pow(N);
        for (int f = 2; f * x <= K; ++f) {
            divCount[x] -= divCount[f*x];
        }
        ans += divCount[x] * x;
    }

    cout << ans.value() << endl;

    return 0;
}


Measured memory_bytes: 4784