akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int N; cin >> N;
    vector<ll> L(N);
    rep(i,N) cin >> L[i];
    
    ll ans = 0;
    rep(i,N) {
        ll a = L[i];
        for (int j = i + 1;j < N;++j) {
            ll b = L[j];
            for (int k = j + 1;k < N;++k) {
                ll c = L[k];
                if (a == b || b == c || c == a) continue;
                if (b + c > a && a + b > c && c + a > b) ++ans;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= 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(ll 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;
  }
};

int main(){
  string l;
  cin >> l;
  vector<vector<mint>> dp(2, vector<mint>(l.size()+1, 0));
  dp.at(0).at(0) = 0;
  dp.at(1).at(0) = 1;
  rep(i, l.size()){
    char now = l.at(i);
    dp.at(0).at(i+1) += dp.at(0).at(i)*3;
    dp.at(1).at(i+1) += dp.at(1).at(i);
    if(now == '1'){
      dp.at(0).at(i+1) += dp.at(1).at(i);
      dp.at(1).at(i+1) += dp.at(1).at(i);
    }
  }
  // rep(i, l.size()+1){
  //   cerr << dp.at(0).at(i).x << " ";
  // }
  // cerr << endl;
  // rep(i, l.size()+1){
  //   cerr << dp.at(1).at(i).x << " ";
  // }
  // cerr << endl;
  mint ans = dp.at(0).at(l.size()) + dp.at(1).at(l.size());
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    vector<string> s(3);
    rep(i,3) cin >> s[i];
    string ans = "A";
    ans += s[1][0]; 
    ans += 'C';
    cout << ans << endl;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6");
            WillReturn.Add("3 1 2 4 2 1");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("1 2 3 4");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("10");
            WillReturn.Add("3 3 3 3 4 4 4 5 5 5");
            //20
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        long[] AArr = InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray();

        var Query = AArr.GroupBy(A => A).OrderByDescending(A => A.Key);
        var HenList = new List<long>();

        foreach (var EachItem in Query) {
            if (EachItem.Count() >= 4) {
                HenList.Add(EachItem.Key);
                HenList.Add(EachItem.Key);
            }
            else if (EachItem.Count() >= 2) {
                HenList.Add(EachItem.Key);
            }
            if (HenList.Count >= 2) break;
        }

        if (HenList.Count >= 2) {
            Console.WriteLine(HenList[0] * HenList[1]);
        }
        else Console.WriteLine(0);
    }
}


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

typedef long long ll;

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

    vector<int> A(N+1);
    vector<int> ans(N+1);

    int total_count = 0;

    for(int i=1; i<=N; i++){
      cin >> A[i];
    }
    for(int i=N; i>=1; i--){
      int now = i;
      int counter = 2;
      int c_sum = 0;
      while(now * counter <= N){
        c_sum += ans[now * counter];
        counter++;
      }
      c_sum = c_sum % 2;
      if(c_sum == A[i]){
        ans[i] = 0;
      }
      else{
        ans[i] = 1;
        total_count++;
      }
    }

    if(total_count == 0){
      cout << 0 << endl;
      return 0;
    }
    cout << total_count << endl;
    for(int i=1; i<=N; i++){
      if(ans[i] == 1){
        total_count--;
        if(total_count > 0){
          cout << i << " ";
        }
        else{
          cout << i << endl;
        }
      }
    }
    return 0;
}

Measured memory_bytes: 2432
#include <cstdio>
#include <algorithm>
using namespace std;

int B[100002], L[100002], U[100002];
int X;

struct Test {
  int i; long long mx;

  bool operator< (Test &r) {
    return mx > r.mx;
  }
};

Test p[100002]; bool vs[100002];

long long fullScore(int i){
  return 1LL * L[i] * B[i] + 1LL * U[i] * (X - B[i]);
}

int reqScore(int i, long long now){
  if(now + 1LL * L[i] * B[i] >= 0){
    return (L[i] - now - 1) / L[i];
  }

  now += 1LL * L[i] * B[i];
  return B[i] + (U[i] - now - 1) / U[i];
}

int main(){
  int N, X; scanf("%d%d", &N, &X); ::X = X;

  for(int i = 1; i <= N; i++){
    scanf("%d%d%d", &B[i], &L[i], &U[i]);
  }

  long long now = 0;
  for(int i = 1; i <= N; i++) now -= 1LL * L[i] * B[i];

  for(int i = 1; i <= N; i++) p[i] = { i, fullScore(i) };

  sort(p + 1, p + N + 1);

  int wall = 0; long long ans = 0;

  for(int i = 1; i <= N; i++){
    if(now + p[i].mx < 0){
      ans += X; now += p[i].mx; vs[p[i].i] = true;
    }
    else{ wall = p[i].i; break; }
  }

  int lst = X;

  for(int i = 1; i <= N; i++){
    if(vs[i]){
      lst = min(lst, reqScore(i, now - fullScore(i) + fullScore(wall)));
    }
    else if(now + fullScore(i) >= 0){
      lst = min(lst, reqScore(i, now));
    }
  }

  printf("%lld\n", ans + lst);
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

struct Cake{
  ll sum, i, j, k;
  bool operator < (const Cake& other) const
  {
    return sum < other.sum;
  }
};

void solve()
{
  int x, y, z, k;
  //*
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  for(int i = 0; i < x; ++i) cin >> a[i];
  for(int i = 0; i < y; ++i) cin >> b[i];
  for(int i = 0; i < z; ++i) cin >> c[i];
  //*/

  /*
  x = y = z = 1000;
  k = min(3000, x*y*z);
  vector<ll> a(x), b(y), c(z);
  for(int i = 1; i <= x; ++i)
  {
    a[i] = i;
    b[i] = i * 10;
    c[i] = i * 100;
  }
  //*/

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());


  auto f = [&](ll arg)
  {
    int cnt = 0;
    for(int ia = 0; ia < x; ++ia)
    {
      for(int ib = 0; ib < y; ++ib)
      {
        for(int ic = 0; ic < z; ++ic)
        {
          if (a[ia] + b[ib] + c[ic] >= arg) cnt++;
          else break;
          if (k <= cnt) return true;
        }
      }
    }
    return false;
  };

  ll le = -1, re = 30000000005LL;
  while(re - le > 1)
  {
    ll mid = (le + re) / 2;
    if ( !f(mid) ) re = mid;
    else le = mid;
  }

  vector<ll> ans;
  for(int ia = 0; ia < x; ++ia)
  {
    for(int ib = 0; ib < y; ++ib)
    {
      for(int ic = 0; ic < z; ++ic)
      {
        ll sum = a[ia] + b[ib] + c[ic];
        if (sum > le) ans.emplace_back(sum);
        else break;
      }
    }
  }

  sort(ans.begin(), ans.end(), greater<ll>());
  while(ans.size() < k)
  {
    ans.emplace_back(le);
  }
  for(const auto& v : ans)
  {
    cout << v << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3724
#ABC079C
def main():
    import sys
    import itertools as ite
    nums = list(map(int, list(sys.stdin.readline().rstrip())))
    ope = list(ite.product(['+', '-'], repeat=3))
    #print(ope)
    
    def calc(L):
        ans = L[0]
        for i in range(1, len(L)-1, 2):
            if L[i] =='+':
                ans +=L[i+1]
            elif L[i] =='-':
                ans -=L[i+1]
        if ans ==7:
            L = ''.join(list(map(str, L)))
            print(L+'=7')
            return True
    
    for op in ope:
        L=[]
        for i in range(3):
            L += [nums[i], op[i]]
        L+=[nums[3]]
        #print(L)
        if calc(L) ==True:
            break
        


if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;
    sort(A.begin(), A.end());
    int ans = 0;
    set<int> explore;
    auto update = [&](int now) {
        for (int i = now; i <= 1e6 + 100; i += now) explore.insert(i);
    };
    set<int> check;
    set<int> outof;
    for (int i = 0; i < N; i++) {
        if (check.find(A[i]) != check.end()) {
            outof.insert(A[i]);
            continue;
        }
        if (explore.find(A[i]) == explore.end()) {
            ans++;
            update(A[i]);
            check.insert(A[i]);
        }
    }
    cout << ans - outof.size() << endl;
}

Measured memory_bytes: 54192
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll PS(ll a,ll b) {
  ll x=1;
  rep(i,b) {
    x*=a;
  }
  return x;
}
    
int main() {
  ll N;
  ll K;
  cin >>N>>K;
  ll ans=0;
  rep(i,40) {
    ll y=PS(K,i);
    
      if(N/y<1) {
      ans=i;
      break;
    }
 else {
continue;
 }
  }
   cout<<ans<<endl;
  }
    
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int a,b,c;
int main()
{
    scanf("%d %d %d",&a,&b,&c);
    printf("%d",min(a+b+1,c)+b);
}


Measured memory_bytes: 3756
fun main(args: Array<String>) {
    val N = nextInt()
    val A = IntArray(N) { nextInt() }
    val S = A.sortedDescending()
    repeat (N) {
        println(if (S[0] == A[it]) S[1] else S[0])
    }
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())


Measured memory_bytes: 57512
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
    int n, m;
    int b, c;
    vector<pair<int, int> > v;

    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0;i < n;i++)
    {
        cin >> a[i];
    }

    for (int i = 0;i < m;i++)
    {
        cin >> b >> c;
        v.push_back(make_pair(c, b));
    }

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    vector<int> aa;
    for (int i = 0;i < m;i++)
    {
        if (aa.size() + v[i].second >= n)
        {
            while(aa.size() < n)
            {
                aa.push_back(v[i].first);
            }
        }else
        {
            for (int j = 0;j < v[i].second;j++)
            {
                aa.push_back(v[i].first);
            }
        }
    }

    for (int i = 0;i < aa.size();i++)
    {
        a.push_back(aa[i]);
    }

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

    long long ans=0ll;
    for (int i = 0;i < n;i++)
    {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2804
import math
from sys import stdin


def get_result(data):
    N = data[0]
    cnt = 0
    val = 100
    while N > val:
        val = math.floor(val * 1.01)
        cnt += 1
    return cnt


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,cnt=0;
    cin>>n>>k;
    if((n-1)*(n-2)/2 < k){
        cout<<-1<<endl;
        return 0;
    }
    int addition = (n-1)*(n-2)/2 - k;
    cout<<n-1+addition<<endl;
    for(int i=2;i<=n;i++)
        cout<<1<<" "<<i<<endl;
    for(int i=2;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(cnt == addition){
                return 0;
            }
            cout<<i<<" "<<j<<endl;
            cnt++;
        }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);

  int ans = 0;
  rep(i, a, b+1) {
    int x = i / 1000;
    int y = i % 100;
    if (x / 10 == y % 10 && x % 10 == y / 10) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

const int MAX_N = 1e5;

long long n, a, b;
long long x[MAX_N];
long long ans;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        if (i == 0) {
            continue;
        }
        ans += min(b, (x[i] - x[i - 1]) * a);
    }
    cout << ans << "\n";
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <vector>
#include <stack>
#include <map>
#include <queue>
#include <string.h>
#include <algorithm>
#include <iostream>
#define ll long long
#define db double
#define INFINITE 9999999

using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int a,b;
    char s[50];
    while(cin>>a>>b){
        sprintf(s,"%d",a+b);
        cout<<strlen(s)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1192
c = input()
sum = 0;
cc = c[0]
if len(c)!=1:
    for i in range(1,len(c)):
        if (c[i]==cc[i-1]):
            sum+=1
            if (c[i]=='1'):
                cc+='0'
            else:
                cc+='1'
        else:
            cc+=c[i]
print(sum)

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<numeric>

using namespace std;

int main(){
    map<string, int> map;
    map["SUN"] = 0;
    map["MON"] = 1;
    map["TUE"] = 2;
    map["WED"] = 3;
    map["THU"] = 4;
    map["FRI"] = 5;
    map["SAT"] = 6;

    string s;
    cin >> s;
    cout << 7 - map[s] << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

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

  if (a>b) {
    for (int ii=0; ii<a; ++ii)
      cout << b;
  } else {
    for (int ii=0; ii<b; ++ii)
      cout << a;
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)

int main(){
    int H,W,K;
    int table[6][6];
    cin>>H>>W>>K;
    string s;
    int sum=0;
    rep(i,H){
        cin>>s;
        rep(j,W){
            if(s[j]=='.') table[i][j] = 0;
            else table[i][j] = 1;
            sum += table[i][j];
            // cout<<table[i][j]<<" ";
        }
        // }cout<<endl;
    }
    ll ans = 0;
    int gyo[6];
    rep(hoge,1<<(H+W)){
        int gyo = hoge%(1<<H);
        int retsu = hoge>>H;
        int dele = 0;
        rep(i,H){
            rep(j,W){
                if(((gyo>>i)&1) || (retsu>>j)&1) dele+=table[i][j]; 
            }
        }
        if(dele == sum-K){
            ans++;
            // cout<<gyo<<" "<<retsu<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

int main(void) {
  string s;
  cin >> s;
  ll i;
  ll cnt=0;
  
  for(i=0; i<s.size(); i++) {
    if(s[i]=='x') cnt++;
  }
  
  if(cnt>=8) pt("NO");
  else pt("YES");
  
  
  
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>

using namespace std;

struct P{int c,r;};
struct State{
  int t,pos, remain;
  bool operator < (const State& st) const {
    return t > st.t;
  }
};

const int MAX = 5001;
const int INF = (1<<25);
int T[MAX][MAX];
vector<int> Edge[MAX];
P price[MAX];
int N,K;

void input(){
  scanf("%d %d",&N,&K);
  for(int i = 0; i < N; i++) scanf("%d %d",&price[i].c, &price[i].r);
  for(int i = 0; i < K; i++){
    int a,b;
    scanf("%d %d",&a, &b);
    a--;b--;
    Edge[a].push_back(b);
    Edge[b].push_back(a);
  }
}

void solve(){
  memset(T, -1, sizeof(T));
  T[0][0] = 0;
  priority_queue<State> Q;
  Q.push((State){0,0,0});
  while(!Q.empty()){
    const State now = Q.top();
    Q.pop();
    
    if(now.t > T[now.pos][now.remain]) continue;
    
    if(now.remain > 0){
      for(int i = 0; i < (int)Edge[now.pos].size(); i++){
	State nex = now;
	nex.pos = Edge[now.pos][i];
	nex.remain--;
	
	if(T[nex.pos][nex.remain] == -1 || T[nex.pos][nex.remain] > nex.t){
	  T[nex.pos][nex.remain] = nex.t;
	  Q.push(nex);
	}
      }
    }

    if(T[now.pos][price[now.pos].r] == -1 || T[now.pos][price[now.pos].r] > now.t+price[now.pos].c){
      T[now.pos][price[now.pos].r] = now.t+price[now.pos].c;
      Q.push((State){now.t+price[now.pos].c, now.pos, price[now.pos].r});
    }
  }
  
  int ans = INF;
  for(int i = 0; i < MAX; i++) 
    if(T[N-1][i] >= 0) ans = min(ans,T[N-1][i]);
  printf("%d\n",ans);
}

int main(){

  input();
  solve();
  return 0;
}

Measured memory_bytes: 99420
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main() {
	char b;

	scanf("%c", &b);

	if (b == 'A') printf("T");
	else if (b == 'T') printf("A");
	else if (b == 'C') printf("G");
	else if (b == 'G') printf("C");

	return 0;
}

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

int main() {
  int n, k;
  std::cin >> n >> k;
  int cnt = 0;
  std::vector<int> v;
  for (int i = 0; i < n; ++i) {
    int l;
    std::cin >> l;
    v.push_back(l);
  }
  std::sort(v.begin(), v.end());
  for (int i = 0; i < k; ++i) {
    cnt += v[n - i - 1];
  }
  std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))

X.sort()
Max = X[len(X)-1]

res=100000000
for i in range(Max+1):
    SUM=0
    for j in range(len(X)):
        SUM += (X[j] - i) ** 2
    res = min(res, SUM)

print(res)

Measured memory_bytes: 9084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] sum = new long[n+1];
		for(int i=0;i<n;i++) {
			sum[i+1] = sum[i] + in.nextLong();
		}
		long min = Long.MAX_VALUE;
		for(int i=1;i<n;i++) {
			long num = abs(sum[i]*2-sum[n]);
			if(num<min) min = num;
		}
		System.out.println(min);
		in.close();

	}
	
	public static long abs(long a) {
		if(a<0) return -a;
		else return a;
	}

}


Measured memory_bytes: 65580
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
const int MAX_N=1<<18;
const ll INF=1e18;
ll mx[2*MAX_N-1], part[2*MAX_N-1];
bool mada[2*MAX_N-1];
int m0;
void init(int n){
    m0=1;
    while(m0<n) m0*=2;
}

void eval(int k, int l, int r){
    if(mada[k]){
        mx[k]+=part[k];
        if(k<m0-1){
            part[2*k+1]+=part[k];
            part[2*k+2]+=part[k];
			mada[2*k+1]=1; mada[2*k+2]=1;
        }
        mada[k]=0;
        part[k]=0;
    }
}

void add(int a, int b, ll x, int k, int l, int r){
    eval(k, l, r);
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){
        part[k]=x;
        mada[k]=1;
        eval(k, l, r);
    }else{
        add(a, b, x, k*2+1, l, (l+r)/2);
        add(a, b, x, k*2+2, (l+r)/2, r);
        mx[k]=max(mx[2*k+1], mx[2*k+2]);
    }
}
     
ll find(int a, int b, int k, int l, int r){
    eval(k, l, r);
    if(b<=l || r<=a){
        return -INF;
    }
    if(a<=l && r<=b){
        return mx[k];
    }else{
        return max(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
    }
}
int main()
{
	int n, m;
	cin>>n>>m;
	ll sum=0;
	vector<P> v[200001];
	for(int i=0; i<m; i++){
		int l, r; ll a;
		cin>>l>>r>>a;
		sum+=a;
		v[r].push_back(P(l, -a));
	}
	ll dp=0; ll ans=0;
	init(n+2);
	for(int i=1; i<=n+1; i++){
		for(auto p:v[i-1]) add(0, p.first, p.second, 0, 0, m0);
		dp=max(dp, find(0, i-1, 0, 0, m0)); ans=max(ans, dp);
		add(i, i+1, dp, 0, 0, m0);
	}
	cout<<sum+ans<<endl;
	return 0;
}

Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
int calculateMex (set<int> Set)
{
	int Mex = 0;
	
	while (Set.find (Mex) != Set.end())
		Mex++;
	
	return (Mex);
}
int Grundy [100000+5];
int a [100000+5];
int calculateGrundy (int n, int k)
{
	if (n == 0)
		return (0);
	if (Grundy[n] != -1)
		return (Grundy[n]);
	
	set<int> Set; // A Hash Table
	
	for(int i=1;i<=k;i++)
	    if (a[i]<=n)
	    Set.insert (calculateGrundy (n-a[i], k));
	Grundy[n] = calculateMex (Set);	
	return (Grundy[n]);
}

// Driver program to test above functions
int main()
{
	int n, k;
	cin >>n>>k;
	memset (Grundy, -1, sizeof (Grundy));
	for(int i=1;i<=n;i++) {
	    cin>>(a[i]);
	    Grundy[a[i]] = a[i];
	}
	cout<<((calculateGrundy(k, n)>0)?"First":"Second");
	//for(int i=0;i<=k;i++) cout<<Grundy[i]<<endl;
	return (0);
}


Measured memory_bytes: 20992
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main(){
	int n;
	cin>>n;
	int even=0,odd=0;
	if(n%2==0){
		double ans=0.5000000000;
		cout<<setprecision(10)<<ans<<endl;
	}else{
		double ans=n/2+1;
		ans/=(double)n;
		cout<<setprecision(10)<<ans<<endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n, a;
    cin >> n;
    if (n % 10 == 9 || n / 10 % 10 == 9)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
int S[10005];
int n,q;
bool linear_search(int key){
	S[n]=key;
	int i=0;
	while (key!=S[i]){
		i++;
	}
	if(i==n)return false;
	return true;
}
int main(){
	int cnt=0,T;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&S[i]);
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&T);
		cnt+=linear_search(T);
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2752
n,k = map(int,input().split())
nnin = []
for m in range(1,n+1):
    nnin.append(m)
for b in range(k):
    d  = int(input())
    a = list(map(int,input().split()))
    for s in a:
        if s in nnin:
            nnin.remove(s)
print(len(nnin))

Measured memory_bytes: 67168
#include<bits/stdc++.h>
using namespace std;
void print(int arr[],int n)
{
    int i;
    for(i=0;i<n-1;i++)
        printf("%d ",arr[i]);
    printf("%d\n",arr[i]);
}
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n+1];
    for(int i=0;i<n;i++)
        scanf("%d",&arr[i]);
    for(int i=0;i<n;i++)
    {
        for(int j=i;j>0;j--)
        {
            if(arr[j-1]>arr[j])
                swap(arr[j],arr[j-1]);
        }
        print(arr,n);
    }
    return 0;
}



Measured memory_bytes: 3152
#include <stdio.h>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {

    int N = 0;
    scanf("%d", &N);

    int tmp = N;

    int S = 0;
    while (tmp) {
        S += tmp % 10;
        tmp /= 10;
    }

    if (N % S == 0) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int A[5],B[5];
string rule[5][5];
#define pb push_back
string s;
int main(void)
{
  while(getline(cin,s) && s!="0")
    {
      int lowerten=0;
      int one=0;
      int score=0;
      int lastscore=0;
      string num="";
      //cout << int(s.size()) << endl;
      for(int i=0;i<int(s.size());i++)
	{
	  if(s[i]!=' ')
	    {
	      num+=s[i];
	    }
	  if(s[i]==' ' || i==int(s.size()-1))
	    {
	      int getnum=stoi(num);
	      if(getnum>=10) score+=10;
	      else if(getnum==1) one++;
	      else score+=getnum;
	      num="";
	    }
	}
      for(int i=0;i<=one;i++)
	{
	  int addscore=11*i+1*(one-i);
	  if(score+addscore>21)
	    {
	      continue;
	    }
	  else
	    {
	      lastscore=max(lastscore,score+addscore);
	    }
	}
      if(score>21)
	{
	  cout << 0 << endl;
	}
      else
	{
	  cout << lastscore << endl;
	}
    }
  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    ll n;
    cin >> n;
    ll ans=to_string(n).length();
    for(ll i=2;i*i<=n;i++){
        ll a=n,b=1;
        if(n%i==0){
            a /= i;
            b *= i;
            ll a_t,b_t;
            a_t = to_string(a).length();
            b_t = to_string(b).length();
            ans = min(ans,max(a_t,b_t));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
x,k,d = gets.split.map &:to_i

if x >= 0 then
	div = x / d
	mod = x % d

	if k > div then
		if (k - div) % 2 == 1 then
			puts (x - div * d - d).abs
		else
			puts (x - div * d).abs
		end
	else
		puts (x - k * d).abs
	end
else
	div = x.abs / d
	mod = x.abs % d

	if k > div then
		if (k - div) % 2 == 1 then
			puts (x + div * d + d).abs
		else
			puts (x + div * d).abs
		end
	else
		puts (x + k * d).abs
	end
end



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

namespace ABC105B
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int N = ConsoleInput.Int();
            
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    if (4 * i + 7 * j == N)
                    {
                        Console.WriteLine("Yes");
                        return;
                    } 
                }
            }
            Console.WriteLine("No");
        }
    }
    
    internal static class ConsoleInput
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

int sum_digit(int n){
  if( n == 0 ) return 0;
  else return n%10 + sum_digit(n/10);
}

int main()
{
  int i,N,K; cin >> N >> K;
  vector<int> l(N);
  for(i = 0; i < N; i++){
  	cin >> l.at(i);
  }
  
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  
  int sum = 0;
  for(i = 0; i < K; i++){
  	sum += l.at(i);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll x = (c+b-1)/(b);
	ll y = (a+d-1)/(d);
	if(x<=y)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3652
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
import sys
sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N = i_inpl()
    if N == 1:
        print(0)
        return
    print(((1+(N-1))*(N-1))//2)
if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
import sys
def input(): return sys.stdin.readline().strip()

class SegTree():
    """
    0-indexedの配列[a0, a1, a2, ..., a(N-1)]に対して以下のクエリをそれぞれO(logx)で行う：
        1. i番目の要素にxを代入
        2. 半開区間[i, j)内の最小値を返す
    self.id_elemとself.funcを変えることでRmQ以外にも例えばRMQに対応可能。
    参考：https://juppy.hatenablog.com/entry/2019/05/02/蟻本_python_セグメント木_競技プログラミング_Atcoder
    """
    def __init__(self, N):
        #####identity element######
        self.id_elem = 0
        self.func = max

        #num_max: the smallest power of two over N
        self.num_max = 2 ** ((N - 1).bit_length())
        self.x = [self.id_elem] * (2 * self.num_max - 1)

    def get_elem(self, i):
        """
        i番目の要素を返す
        """
        return self.x[self.num_max + i - 1]

    def update(self, i, x):
        """
        i番目の要素にxを代入
        """
        i += self.num_max - 1
        self.x[i] = x
        while (i > 0):
            i = (i - 1) // 2
            self.x[i] = self.func(self.x[i * 2 + 1], self.x[i * 2 + 2])

    def query(self, i=0, j=-1):
        """
        半開区間[i, j)内の最小値を返す
        query()で配列全体に対してクエリを実行する
        """
        if j == -1: j = self.num_max
        i += self.num_max - 1
        j += self.num_max - 1
        res = self.id_elem
        
        while i < j:
            if i % 2 == 0:
                res = self.func(res, self.x[i])
                i += 1
            if j % 2 == 0:
                res = self.func(res, self.x[j - 1])
            i = (i - 1) // 2
            j = (j - 1) // 2
        return res

def main():
    N, K = map(int, input().split())
    """
    愚直に解けそうに無いのでdpを考える：dp[i][j] = (0~i番目まで見た時に最後の数がjで終わる部分列の最大長)
    このdpはO(N^2)なのでそのままでは実行不可能だが、ひとまず遷移を考えてみると
        dp[i][j] = max(dp[i-1][j-K], dp[i-1][j-K+1], ..., dp[i-1][j+K]) + 1
    ここのmaxをセグ木で導出すれば計算量はO(NlogN)で間に合う。
    """
    dp = SegTree(300001)
    for _ in range(N):
        a = int(input())
        # 最後がaで終わるケースのみ更新が入る
        now = dp.query(max(0, a - K), min(300001, a + K + 1))
        dp.update(a, now + 1)
    print(dp.query())


if __name__ == "__main__":
    main()


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

void Main() {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
  }
  if (sum >= h) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
result = float("inf")


def search(subset, depth, costs, x):
    if depth == len(costs):
        local_res = 0
        knowledge = [0] * (len(costs[0]) - 1)
        for i, cost in enumerate(costs):
            if i in subset:
                local_res += cost[0]
                for i, c in enumerate(cost[1:]):
                    knowledge[i] += c
        if done(knowledge, x):
            global result
            result = min(result, local_res)
    else:
        search(subset, depth + 1, costs, x)
        subset.add(depth)
        search(subset, depth + 1, costs, x)
        subset.remove(depth)


def done(knowledge, x):
    for item in knowledge:
        if item < x:
            return False
    return True


def solve(costs, x):
    search(set(), 0, costs, x)

    if result == float("inf"):
        return -1

    return result


if __name__ == "__main__":
    n, m, x = map(int, input().split())
    costs = [[int(x) for x in input().split()] for y in range(n)]
    print(solve(costs, x))


Measured memory_bytes: 9268
<?php

$h = STDIN;
fgets($h);
$str = fgets($h);
list($a, $b) = explode(' ', $str);

$tmp = array_map(function ($a, $b) {
    return $a.$b;
}, str_split($a), str_split($b));

$ans = implode('', $tmp);
echo $ans;




Measured memory_bytes: 4728
#include <stdio.h>
int main(){
    int sec=0;
    int min=0;
    int h=0;
    int S=0;
    scanf("%d", &S);
    h = S/3600;
    min= (S-h*3600)/60;
    sec= S-(h*3600+min*60);
    printf("%d:%d:%d\n", h, min, sec);
    return 0;
}

Measured memory_bytes: 592
N, M = map(int, input().split())
h = list(map(int, input().split()))

ans = {}

for i in range(M):
    a, b = list(map(int, input().split()))

    if h[a - 1] > h[b - 1]:
        ans[b - 1] = False
    elif h[a - 1] < h[b - 1]:
        ans[a - 1] = False
    else:
        ans[a - 1] = False
        ans[b - 1] = False

print(N - len(ans))


Measured memory_bytes: 19884
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

int x, y, a, b, c;
std::vector<int> va, vb, vc;

int main()
{
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	for (int i = 0; i < a; ++i)
	{
		int k; scanf("%d", &k);
		va.push_back(k);
	}
	std::sort(va.begin(), va.end(), std::greater<int>());
	while (va.size() > x) va.pop_back();
	//for (int x : va) printf("va %d\n", x);
	for (int i = 0; i < b; ++i)
	{
		int k; scanf("%d", &k);
		vb.push_back(k);
	}
	std::sort(vb.begin(), vb.end(), std::greater<int>());
	while (vb.size() > y) vb.pop_back();
	//for (int x : vb) printf("vb %d\n", x);
	for (int i = 0; i < c; ++i)
	{
		int k; scanf("%d", &k);
		vc.push_back(k);
	}
	for (int a : va) vc.push_back(a);
	for (int b : vb) vc.push_back(b);
	std::sort(vc.begin(), vc.end(), std::greater<int>());
	long long sum = 0;
	for (int i = 0; i < x + y; ++i)
		sum += vc[i];
	printf("%lld\n", sum);
}

Measured memory_bytes: 3188
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

//Ordered Set Implementaton:

/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less_equal<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;*/

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    ld a, b, c;
    cin >> a >> b >> c;
    ld diff = c - a - b;
    ld calc = 2.0 * sqrt(a * b);
    if(diff > calc){
        cout << "Yes\n";
    }
    else cout << "No\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
namespace bf
{
	typedef long long ll;
	int n;
	long double a,x;
	long double ans;
	void solve()
	{
		scanf("%d%Lf%Lf",&n,&a,&x);
		ans=0;
		while(n)
		{
			ans+=(a+a+(2*n-1)*x)*0.5;
			a=((n*2+2)*a+x*5)/(2*n);
			x=x*(n+2)/n;

			n--;
		}
		printf("%.15Lf\n",ans);
	}
}
int main()
{
	bf::solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstring>

#define ll long long
const ll MOD = 1e9 + 7;

int main()
{
    std::ios::sync_with_stdio(false);

    ll N;
    std::cin >> N;

    std::vector<ll> BIT(N+1, 0);

    std::vector<ll> a(N);
    for (int i=0; i<N; ++i)
    {
        std::cin >> a[i];
        BIT[i+1] = a[i] + BIT[i];
    }

    // BIT[to] - BIT[from] == 0 のときが解の候補なので
    // 並び替えて同じ数字が何連続するか調べる
    std::sort(BIT.begin(), BIT.end());

    ll previous = BIT[0];
    ll ans = 0;
    ll n = 1;
    for (int i=1; i<=N; ++i)
    {
        //連続した区間を計測
        if (previous == BIT[i])
            n++;

        //BIT列の終端が同じ数字だった場合もカウント
        if (previous != BIT[i] || i == N)
        {
            ans += n * (n - 1) / 2;
            n = 1;
        }

        previous = BIT[i];
    }

    std::cout << ans << std::endl;
}

Measured memory_bytes: 3456
N = int(raw_input())
word = [raw_input()]
for i in range(1, N):
	newword = raw_input()
	if newword in word or newword[0] != word[-1][-1]:
		print 'No'
		break
	if i == N-1: print 'Yes'
	else: word.append(newword)

Measured memory_bytes: 27628
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(count(N, 0));
	}
	
	public static int count(int num, int cnt) {
		if(num < 6) {
			return cnt + num;
		}
		int a = 1;
		int b = 1;
		while(num >= a * 6) a *= 6;
		while(num >= b * 9) b *= 9;
		return Math.min(count(num - a, cnt + 1), count(num - b, cnt + 1));
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define FI first
#define SE second
using namespace std;
static const int inf = 1ll<<60;
typedef pair<int,int> pii;
string S;
bool n=false,s=false,e=false,w=false;

signed main(){
    cin>>S;
    for(int i=0;i<S.size();++i){
        if(S[i]=='N')n=true;
        if(S[i]=='S')s=true;
        if(S[i]=='E')e=true;
        if(S[i]=='W')w=true;
    }
    if(n&&s&&e&&w)cout<<"Yes"<<endl;
    else if(n&&s&&!e&&!w)cout<<"Yes"<<endl;
    else if(!n&&!s&&e&&w)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int,input().split())
s = list(map(str,input()))

hp = 0
uhp = 0

for i in range(n-1):
    if s[i] == s[i+1]:
        hp += 1
    else:
        uhp += 1

print(min(n-1,hp+(min(uhp,k))*2))

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

int main() {
  for(int M, T, P, R; cin >> M >> T >> P >> R && (M|T|P|R);) {
    vector<int> ac(T, 0), ti(T, 0);
    vector<vector<int> > wa(T, vector<int>(P, 0));
    for(int i = 0; i < R; ++i) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      if(j) {
        ++wa[t-1][p-1];
      } else {
        ++ac[t-1];
        ti[t-1] += m + wa[t-1][p-1] * 20;
      }
    }
    vector<vector<int> > v;
    for(int i = 0; i < T; ++i) {
      vector<int> u(3);
      u[0] = ac[i];
      u[1] = -ti[i];
      u[2] = i+1;
      v.push_back(u);
    }
    sort(v.begin(), v.end(), greater<vector<int> >());
    for(int i = 0; i < v.size(); ++i) {
      if(i) {
        cout << (v[i-1][0] == v[i][0] && v[i-1][1] == v[i][1] ? '=' : ',');
      }
      cout << v[i][2];
    }
    cout << endl;
  }
  return 0;
}

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

double a[5];
double b[5];
int c[5];
int d[5];
int ans;

int main() {
	
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		b[i] = a[i] / 10;
		b[i] += 0.9;
		c[i] = b[i];
		c[i] *= 10;
		d[i] = c[i] - a[i];
	}
	
	sort(d, d + 5);

	for (int i = 0; i < 5; i++) {
		ans += c[i];
	}

	ans -= d[4];

	cout << ans << endl;

	system("pause");
	return 0;
}



Measured memory_bytes: 504
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")
    };
}



fn main() {
    input!{
        n: usize,
        k: usize,
        a: [i32; n],
    }
    for i in (k)..n {
        if a[i-k] < a[i] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 2772
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;



int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,range=0,fir=0,sec=0;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0;
    //vector <int> v;
    //float f,g,h;
    char now,pre;
    //string a;
    cin>>n;
    long long int num[3*n];
    for(i=0;i<3*n;i++) cin>>num[i];
    sort(num,num+3*n,greater<int>());
    for(i=0,j=1;i<n;i++,j+=2)
        sum+=num[j];
    cout<<sum;
    return 0;
}





Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll INF=1000000000009;
bool comp(const P &a,const P &b){
	return a.second<b.second;
}

ll closest_pair(P *a,int n){
	if(n<=1)return INF;
	int m=n/2;
	ll x=a[m].first;
	ll d=min(closest_pair(a,m),closest_pair(a+m,n-m));
	inplace_merge(a,a+m,a+n,comp);
	
	vector<P> b;
	for(int i=0;i<n;i++){
		if(abs(a[i].first-x)>=d)continue;
		for(int j=0;j<b.size();j++){
			ll dx=a[i].first-b[b.size()-j-1].first;
			ll dy=a[i].second-b[b.size()-j-1].second;
			if(dy>=d)break;
			d=min(d,dx*dx+dy*dy);
		}
		b.push_back(a[i]);
	}
	return d;
}

int n;
P data[600001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld%lld",&data[i].first,&data[i].second);
	sort(data,data+n);
	printf("%lld\n",closest_pair(data,n));
	return 0;
}

Measured memory_bytes: 22024