akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false),in.tie(0),cout.tie(0);
#define input freopen("input.in","right_interval",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define si(x) scanf("%d",&x)
#define sf(x) scanf("%f",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x);
#define pf(x) printf("%f",x);
#define pl(x) printf("%lld",x);
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;
//ifstream in("input.txt");
//ofstream out("output.txt");
void solve();
int main()
{
  int t=1;
//  si(t);
  rep(i,1,t)
  {
    solve();
    if(i!=t) e
  }
  return 0;
}
int dp[mx][3];
int ar[mx][3];
void solve()
{
  int i,j,k,m,K,n;
  si(n);
  rep(i,0,n-1) 
  {
    rep(j,0,2) si(ar[i][j]);
  }
  dp[0][0]=max(ar[0][1],ar[0][2]);
  dp[0][1]=max(ar[0][2],ar[0][0]);
  dp[0][2]=max(ar[0][0],ar[0][1]);  
  rep(i,1,n-1)
  {
    dp[i][0]=ar[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=ar[i][1]+max(dp[i-1][2],dp[i-1][0]);
    dp[i][2]=ar[i][2]+max(dp[i-1][0],dp[i-1][1]);    
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}





























Measured memory_bytes: 2560
// finish date: 2019/10/30

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, K;
    cin >> N >> K;
    vi V(N);
    rep(i, N) {
        cin >> V[i];
    }
    int ma = 0;

    rep(l, N + 1) {
        FOR(r, l-1, N) {
            vi have;
            rep(i, l) {
                have.push_back(V[i]);
            }
            FOR(i, r + 1, N) {
                have.push_back(V[i]);
            }
            sort(have.begin(), have.end());
            if (have.size() > K) continue;
            int res = min(have.size(), K - have.size());
            int tmp = 0;

            rep(i, res) tmp += max(have[i], 0);
            FOR(i, res, have.size()) tmp += have[i];
            ma = max(ma, tmp);
        }
    }
    cout << ma << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

int main() {
  int n, k;
  std::cin >> n >> k;
  
  std::vector<int> h(n);
  for (auto&& hi : h) std::cin >> hi;
  
  std::sort(h.begin(), h.end());
  
  int min = std::numeric_limits<int>::max();
  for (int i = 0; i < n - k + 1; ++i)
    min = std::min(min, h[i + k - 1] - h[i]);
  
  std::cout << min << std::endl;
}

Measured memory_bytes: 640
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

  vector<ll> lst(N);
  vector<ll> olst(N);
  for (int i = 0; i < N; i++) {
    cin >> lst[i];
    olst[i] = lst[i];
  }

  sort(lst.begin(), lst.end());
  int pos = N / 2 - 1;
  ll smed = lst[pos];
  ll bmed = lst[pos + 1];
  for (int i = 0; i < N; i++) {
    if (olst[i] <= smed)
      cout << bmed << endl;
    else
      cout << smed << endl;
  }

  return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
#include <stdlib.h>
int main(){
  long int A,B,N,max,y,s,i;
  scanf("%ld %ld %ld",&A,&B,&N);
  if(N>=B) y=B-1;
  else y=N;
  s=y/B;
  max=A*y/B-A*s;
  printf("%ld",max);
  return 0;
}

Measured memory_bytes: 1728
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    double n;
    double ans = 0;
    double x[10],y[10];
    
    cin >> n;
    rep(i,n) cin >> x[i]>>y[i];
    
    double tmp = 2;
    for(double i=2;i<=n-1;i++){
        tmp = tmp*i;
    }
    
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(i!=j){
                double add = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
                ans += add*tmp;
            }
        }
    }
    
    double t=1;
    for(int i=1;i<=n;i++){
        t = t*(double)i;
    }
    
    ans = ans/t;
    cout << setprecision(10)<<ans<<endl;
    
    return 0;
}


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

int main(){
  long long N;
  cin >> N;
long long ANS = N/10;
  long long anz = N - ANS*10;
  if(anz == 3){
    cout << "bon" << endl;
  }
  else if(anz == 0||anz == 1||anz == 6||anz == 8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String W = sc.next();
		int count = 0;

		for (String T = sc.next(); !(T.equals("END_OF_TEXT")); T = sc.next()) {
			T = T.toLowerCase();
			if (W.equals(T)) {
				count++;
			}
		}
		System.out.println(count);

	}

}



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

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return

#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define repd(i,a,b) for (ll i = (a); i >= b; i--)
#define repdz(i,a) for (ll i = a; i >=0; i--)
#define trav(a, x) for (auto& a : x)

#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define llin(a) ll a; cin>>a;
#define llin2(a,b) ll a,b; cin >>a>>b;
#define llin3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define full(v) v.begin(),v.end()

void solve()
{
    string s;
    cin >> s;

    int cur = 0;
    int mul=  1;
    vi cnt(2019);
    cnt[0] = 1;

    for (int i = s.size()-1; i >=0; i--)
    {
        cur += mul*(s[i]-'0');
        cur %= 2019;
        cnt[cur]++;
        mul = (mul*10) % 2019;
    }


    ll ans = 0;
    for (int c : cnt)
    {
        ans += (ll)(c-1)*c/2;
    }

    cout << ans << "\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    //llin(t);
    //while (t--)
    //{
        solve();
    //}
}


Measured memory_bytes: 3800
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>

using namespace std;

void solve() {
    int a,p; cin >> a >> p;
    cout << ((a*3+p)/2) << endl;
}

int main() {
    solve();
    return 0;
}

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

int main(){
  
  long long N, i, a, Kumi = 0;
  cin >> N;
  vector<long long> _A(N);
  map<long long, long long> A;
  
  for (i = 0; i < N; i++){
    
    cin >> a;
    _A.at(i) = a;
    A[a]++;
  }
  
  for (auto y : A) Kumi += y.second * (y.second - 1) / 2;

  for (i = 0; i < N; i++){
    cout << Kumi - A[_A.at(i)] + 1 << endl;
  }
  return 0;
}

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

using namespace std;

const int N = (int)4e6 + 3;

int n;
bitset< N > dp;

int main() {
  scanf("%d", &n);
  int S = 0;
  dp[0] = 1;
  for(int i = 0; i < n; ++i) {
    int x; scanf("%d", &x);
    S += x;
    dp |= dp << x;
  }
  S = (S + 1) / 2LL;
  for(int i = S;; ++i) {
    if(dp[i]) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int A, B, C;
  while (cin >> A >> B >> C) {
    int res = min(B / A, C);
    cout << res << endl;
  }
  return 0;
}


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

using namespace std;

int chartoi(char ch) {
	return ch - '0';
}

int main() {
	string str;

	cin >> str;

	int ans = (int)1.0e9, num;

	for (int i = 0; i < str.length() - 2; i++) {
		num = chartoi(str[i]) * 100 + chartoi(str[i + 1]) * 10 + chartoi(str[i + 2]);
		ans = min(ans, abs(num - 753));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long a = kb.nextLong();
		long b = kb.nextLong();
		long k = kb.nextLong();
		if (a >= 0) {
			if (a <= k) {
				k = k - a;
				a = 0;
			} else {
				a = a - k;
				k = 0;
			}
		}
		//System.out.println(k);
		if (b >= 0) {
			if (b <= k) {
				k = k - b;
				b = 0;
			} else {
				b = b - k;
				k = 0;
			}
		}
		System.out.println(a + " " + b);
		kb.close();
	}

}


Measured memory_bytes: 21844
#include<iostream>
#define S 10001
#define T 1261
using namespace std;

int main(){
  int N,M,r,q;
  int ti[S],n[S],m[S],s[S],time[T],f[S];
  int bti,ati,st,anst;
  while(1){
    cin>>N>>M;
    if(N+M==0) break;
    cin>>r;
    for(int i=0;i<r;i++) cin>>ti[i]>>n[i]>>m[i]>>s[i];
    cin>>q;
    for(int i=0;i<q;i++){
      anst=0;
      cin>>bti>>ati>>st;
      for(int q=0;q<T;q++) time[q]=0;
       
      for(int j=0;j<r;j++){
	if(s[j]==1 && m[j]==st)f[j]=1;
	for(int k=j+1;k<r;k++)
	  if(s[k]==0 && m[k]==st && n[k]==n[j] && f[j]==1){
	    f[j]=0;
	    for(int l=ti[j]+1;l<=ti[k];l++)
	      if(time[l]==0 && l>bti && l<=ati){
		time[l]=1;
		anst++;
	      }
	  }
      }
      cout<<anst<<endl;
    }
  }
  return 0;
}

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

char a[10][10];
bool flag=false;
int H,W,need=0;

void dfs(int i,int j,int cnt) {
  if (i==H-1 && j==W-1 && cnt==need)
    flag=true;
  if (i+1<H && a[i+1][j]=='#')
    dfs(i+1,j,cnt+1);
  if (j+1<W && a[i][j+1]=='#')
    dfs(i,j+1,cnt+1);
}

int main() {
  cin>>H>>W;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin>>a[i][j];
      if(a[i][j]=='#') need++;
    }
  }

  dfs(0,0,1);
  if (flag)
    cout<<"Possible"<<endl;
  else
    cout<<"Impossible"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    for(int i = 1; i*(i-1) <= 2*n; ++i) if(2*n == i*(i-1)){
        cout << "Yes" << endl;
        cout << i << endl;
        vector<int> floornum(i);
        int cnt = 1;
        for(int j = 1; j <= i-1; ++j){
            cnt += j-1;
            floornum[j] = cnt;
        }
        for(int j = 1; j <= i-1; ++j){ //j:段数
            cout << i-1 << " ";
            cout << floornum[j] << " ";
            //横に動く部分
            for(int k = 1; k < j; ++k){
                cout << floornum[j]+k << " ";
            }
            //縦に動く部分
            for(int k=j+1; k <= i-1; ++k){
                cout << floornum[k]+j-1 << " ";
            }
            cout << "\n";
        }
        cout << i-1 << " ";
        //ななめの集合
        cnt = 0;
        for(int j = 1; j <= i-1; ++j){
            cnt += j;
            cout << cnt << " ";
        }
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 1408
/**
 *    author:  tourist
 *    created: 17.12.2019 17:38:40       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n);
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = (int) 2e9;
    for (int j = 0; j < min(i, k); j++) {
      dp[i] = min(dp[i], dp[i - j - 1] + abs(h[i] - h[i - j - 1]));
    }
  }
  cout << dp.back() << '\n';
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  char C[H][W];
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> C[i][j];
    }
  }
  
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cout << C[i][j];
    }
    cout << endl;
    for(int j = 0; j < W; j++) {
      cout << C[i][j];
    }
    cout << endl;
  }

  
  return 0;
}

Measured memory_bytes: 256
#include <string.h>
#include <stdio.h>
#include <math.h>
int main ()
{
    int n, c=0;
    scanf ("%d", &n);
    int a[n];
    for (int i=0;i<n;i++) {
        scanf ("%d", &a[i]);
        if (a[i]!=i+1) c++;
    }
    if (c>2) printf ("NO");
    else printf ("YES");
}



Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long  n;
  cin >> n;
  long long a[n];
  for (int i =0; i<n; i++) cin >> a[i];
  sort(a,a+n);
  long  max = a[n-1];
  long double  dif = 1000000000;
  long double  target  = max/2.0;
  long  ans = a[0];
  for (int i =0; i<n; i++){
    long double c = abs(a[i]-target);
    if(dif> c)  ans = a[i];
    dif = min(dif,c);
  }
    
  
  cout << max <<" "<< ans  << endl;
}

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

int main()
{
    long x, a, b;
    cin >> x;
    a = (x / 500)*1000;
    b = (x % 500) / 5 * 5;
    //cout << a << " " << b << endl;
    cout << a + b << endl;
}

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

namespace AtCoder.Abc140
{
    //https://atcoder.jp/contests/abc139/tasks/abc139_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            Console.WriteLine(Math.Pow(n, 3));
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>
#include <climits>
#include <cstdint>
#include <chrono>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    int w, h, c;
    cin >> w >> h >> c;
    cout << (w / __gcd(w, h)) * (h / __gcd(w, h)) * c << endl;
}

// 1 2 1 2


Measured memory_bytes: 3200
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
ll comb(ll n){
    return n*(n-1)/2;
}


int main() {
    
    ll n;
    cin>>n;
    vector<ll> s(n+1);
    s[0]=0;
    map<ll,ll> m;
    m[0]++;
    rep(i,n){
        ll k;
        cin>>k;
        s[i+1]=s[i]+k;
        m[s[i+1]]++;
    }
    ll ans=0;
    for(auto &a:m){
        
        ll j=a.second;
        ans+=comb(j);
    }
    cout<<ans<<endl;
    
    
    
    

    return 0;
}


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

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i=0; i<N; i++) cin>> A[i];

  long long res=0;
  for (int d=39; d>=-1; d--) { //d=-1はx=kの時
      if (d != -1 && (K & (1LL<<d)) == 0) continue;

      long long tmp=0;
      for (int e=39; e>=0; e--) {
        long long mask = 1LL << e;
        int num=0;
        for (int i=0; i<N; i++) if (A[i] & mask) num++;

        if (e>d) {
          if (K & mask) {
            tmp += mask*(N-num);
          } else {
            tmp += mask*num;
          }
        } else if (e==d) {
          tmp += mask*num;
        } else {
          tmp += mask * max(num, N-num);
        }
      }
      res = max(tmp,res);
  }
  cout << res << endl;
}

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

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	set<int> nums;
	nums.insert(A);
	nums.insert(B);
	nums.insert(C);

	if (nums.size() == 2)cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(a>=b){
    cout<<"delicious"<<endl;
  }
  else if(a+x>=b){
    cout<<"safe"<<endl;
  }
  else{
    cout<<"dangerous"<<endl;
  }
}

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

public class MainClass
{
	public static void Main(string[] args)
	{
		string[] r = Console.ReadLine().Split(' ');
		int n = int.Parse(r[0]);
		int k = int.Parse(r[1]);
		double goukei=0;
		for(int i = 0; i < n; i++)
		{
			//me ga n no toki
			int d=i+1;
			int cnt=0;
			while(d<k)
			{
				d*=2;
				cnt++;
			}
			goukei += (1d/n) * Math.Pow(2,cnt*-1);
		}
		Console.WriteLine(goukei);
	}

	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}


}

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

int main() {
  string A, B;
  cin >> A >> B;
  
  if (A == B) {
    cout << "EQUAL" << endl;
    return 0;
  }
  if (A.size() > B.size()) {
    cout << "GREATER" << endl;
    return 0;
  }
  if (A.size() < B.size()) {
    cout << "LESS" << endl;
    return 0;
  }
  
  for (int i = 0; i < A.size(); i++) {
    if (A[i] > B[i]) {
      cout << "GREATER" << endl;
      return 0;
    }
    else if (A[i] < B[i]) {
      cout << "LESS" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    
    int n = scan.nextInt();
    
    String[] s=new String[n];
    
    for(int i=0;i<n;i++){
    	s[i] = scan.next();
    }

    int m = scan.nextInt();
    

    String[] t=new String[m];
    
    for(int i=0;i<m;i++){
    	t[i] = scan.next();
    }
    
    int point=0;
    
    int count=0;
    
    for(int i=0;i<n;i++){
    	count=0;
    	for(int j=0;j<n;j++){
    		if(s[i].equals(s[j])){
    			count++;
    		}
    	}
    	for(int k=0;k<m;k++){
    		if(s[i].equals(t[k])){
    			count--;
    		}
    	}
    	if(count>point){
    		point=count;
    	}
    }

	System.out.println(point);


  }
}

Measured memory_bytes: 21844
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
c = Counter(a)
res = 0
for key in c.keys():
    # print(key)
    if c[key] >= key:
        res += c[key] - key
    else:
        res += c[key]
print(res)

Measured memory_bytes: 95208
/**
*   @Author : MeGaCrazy
*   @InitTime : Sun Dec 30 01:52:56 2018
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
    string s;
    int ans=0;
    cin>>s;
    for(int i=0;i+1<s.size();i++){
    	if(s[i]!=s[i+1])ans++;
    }
    printf("%d",ans);



}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>

int main() {

    int N, X, A, tmp1, tmp2, i = 0, ans = 0, cst = 1;

    std::cin >> N >> X;

    int L[N];

    while(std::cin >> tmp1){
        L[i] = tmp1;
        i++;
        if(i >= N){
            break;
        }
    }

    int D_cur = 0;
    int D_pre = 0;
    ans++;

    for(int j = 1;j < N+1; j++){
        D_cur = D_pre + L[j-1];
        if(D_cur > X){
            break;
        }
        ans++;
        D_pre = D_cur;
    }
    std::cout << ans << std::endl;

    return 0;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,count=0;
    double k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        double x,y;
        cin>>x>>y;
        double z=sqrt(pow(x,2)+pow(y,2));
        if(z<=k)
        count++;
    }
    cout<<count;
    return 0;
}

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

int main() {
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int dy=y2-y1;
  int dx=x2-x1;
  cout<<x2-dy<<" "<<y2+dx<<" "<<x1-dy<<" "<<y1+dx<<endl;
}


Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $min = PHP_INT_MAX;
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  
  $ans = 5+intdiv($n,$min);
  if($min == 1){
      $ans--;
  }else if($min == $n){
      $ans = 5;
  }
  echo $ans;

Measured memory_bytes: 4728
#include<stdio.h>

int main()
{
    int f = 0, s = 0, t = 0;

    for (int i = 0; i < 10; i++) {
	int h;
        scanf("%d", &h);
	if (f < h) {t = s; s = f; f = h;}
	else if (s < h) {t = s; s = h;}
	else if (t < h) t = h;
    }

    printf("%d\n%d\n%d\n", f, s, t);

    return 0;
}


Measured memory_bytes: 2060
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    ll n; cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ans += (n / i) * (n / i + 1) * i / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int K = sc.nextInt();
		
		char x = S.charAt(K - 1);
		char[] Sh = new char[S.length()];
		String Sf = "";
		
		for(int i = 0; i < S.length(); i++) {
			Sh[i] = S.charAt(i);
			if(Sh[i] != x) {
				Sh[i] = '*';
			}
			Sf += Sh[i];
		}
		
		System.out.println(Sf);
		
	}
}


Measured memory_bytes: 22100
#include <stdio.h>

int main(){
  
  int K;
  scanf("%d",&K);
  
  int even,odd;
  if(K % 2 == 1){
    even = (K - 1) / 2;
    odd = (K + 1) / 2;
  }else{
    even = K / 2;
    odd = K / 2;
  }
  
  int ans = even * odd;
  printf("%d",ans);
  
  return 0;
}
  

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

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

	int max;
	cin >> max;
	int ret = 1;
	for (int i = 1; i < n; ++i) {
		int h;
		cin >> h;
		if (max <= h) {
			++ret;
			max = h;
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<string>
using namespace std;
int main() {
string S;
cin >> S;
int count = 0;
for (int i = 0; i < S.size(); i++){
if (S[i] == '1') {count++;}
}
cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX(a,b) (a>b?a:b)

int main()
{
    int i, n, nn;
    int count = 0;
    scanf("%d",&n);
    nn = n;
    while(nn > 0) {
        int temp = nn % 10;
        if(temp==2)count++;
        nn /= 10;
    }
    printf("%d",count);
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int maxn = 1e6 + 5;

int n;
pair<int,int> a[maxn];
int ans[maxn];

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

  cin>>n;
  for (int i=1; i<=n; i++) {
    cin>>a[i].first; a[i].second=i;
  }
  sort(a+1,a+1+n);
  int lo = a[n/2].first;
  int hi = a[n/2 + 1].first;
  for (int i=1; i<=n; i++) {
    int x = a[i].second;
    if (i<=n/2) {
      ans[x]=hi;
    } else {
      ans[x]=lo;
    }
  }

  for (int i=1; i<=n; i++) {
    cout<<ans[i]<<'\n';
  }
  
  

  return 0;
}


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

typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < n; i++)

/* print like python */
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

bool check(char c){
    return (c=='A' || c=='C' || c=='G' || c=='T');
}
int main()
{
    string s;
    cin >> s;
    int ans=0,cnt=0;
    REP(i,s.length()){
        if(check(s[i])){
            cnt +=1;
            ans = max(ans,cnt);
        }else{
            cnt=0;
        }
    }
    print(ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int n; cin>>n;
    vector<int> a(n);
    int ans = 0;
    vector<int> b(1000005, 0);

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

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


    for (int q : a) {
        if(b[q] != 0){
            b[q] = 2;
            continue;
        }
        for (int i = q; i < 1000005; i+=q) {
            b[i]++;
        }
    }

    for(int p : a){
        if(b[p] == 1) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A,B,i;
  cin >> A >> B;
  i=0;
  while (i < 20){ 
    if (A*i - i + 1 >= B ){
      break;
    }
     else  { 
       i++;
     }
    }
  cout << i << endl;
}

  

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

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int r = in.nextInt();
        out.println(3 * r * r);
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x,ans=1;
    cin>>a>>b;
    if(b==1){cout<<0;return 0;}
    x=a;
    while(x<b){
        x-=1;
        x+=a;
        ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
"""入力に長さ6の文字列，出力は文字列の中の1の数"""

def main():
    """実行部"""
    decision_string = input()
    counter = 0
    for each_sentence in decision_string:
        if each_sentence == "1":
            counter += 1
    print(counter)
    return None

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p;
  while(cin>>n,n){
    vector<int>v;
    for(int i=0;i<n;i++){
      cin>>p;
      v.push_back(p);
    }
    for(int o=0;o<=10000;o++){
      int c=0;
      for(int i=0;i<v.size();i++)
        if(v[i]==i+1)c++;
      if(c==v.size()){
        cout<<o<<endl;
        break;
      }
      int pp=0;
      for(int i=0;i<v.size();i++)
        v[i]--,pp++;
      v.push_back(pp);
      for(int i=0;i<(int)v.size();i++)
        if(!v[i])v.erase(v.begin()+i),i--;
      if(o==10000)cout<<-1<<endl;
    }
  }
}

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

int main() {

	int n; cin >> n;
	const  int p = 8;
	vector<int> num(p + 1, 0);
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a < 3200) num[a / 400]++;
		else num[p]++;
	}
	int	minCnt = 0;
	for (int i = 0; i < p; i++) {
		if (0 < num[i]) minCnt++;
	}
	if (minCnt == 0) {
		cout << 1 << " " << num[p] << endl;
	}
	else cout << minCnt << " " << minCnt + num[p] << endl;
    return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>A(N); rep(i, 0, N) { cin >> A[i]; }

	int sum = 0;
	rep(i, 0, N) {
		if (i % 2 == 0) {
			sum += A[i];
		}
		else {
			sum -= A[i];
		}
	}
	assert(sum % 2 == 0);

	int x = sum / 2;
	vector<int>ans(N);
	ans[0] = x;
	rep(i, 1, N) {
		ans[i] = A[i - 1] - ans[i - 1];
	}
	assert(ans[0] == A[N - 1] - ans[N - 1]);

	rep(i, 0, N)cout << ans[i] * 2 << (i == N - 1 ? '\n' : ' ');

	return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  ll n,m;cin>>n>>m;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  ll sum=0;
  ll left=0;ll right=a[n-1]*2+1;
  ll ans=0;
  while(right-left>1){
    ll mid=(left+right)/2;
    sum=0;
    rep(i,n){
      ll buf=mid-a[i];
      auto it=lower_bound(a.begin(),a.end(),buf);
      ll k=it-a.begin();
      sum+=n-k;
    }
    if(sum<=m)right=mid;
    else if(sum>m)left=mid;
  }
//  cout<<right<<endl;
  vector<ll> b(n+1,0);b[n-1]=a[n-1];
  rep1(i,n-1){
    b[n-1-i]=b[n-i]+a[n-1-i];
  }
    rep(i,n){
    ll buf=right-a[i];
    auto it=lower_bound(a.begin(),a.end(),buf);
    ll k=it-a.begin();
    ans+=(n-k)*a[i]+b[k];
    m-=n-k;
  }
  ans+=m*left;
  if(n*n==m){
    ans=(n+1)*b[0];
  }
  std::cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1920
N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))
import bisect
ans = 0
for b in B:
    i = bisect.bisect_left(A,b)
    j = bisect.bisect_right(C,b)
    ans += i * (N-j)
print(ans)

Measured memory_bytes: 26972
using System;
using CompLib.Util;

public class Program
{
    private int N;
    private long[] A;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.LongArray();

        long other = 0;
        for (int i = 2; i < N; i++)
        {
            other ^= A[i];
        }

        // xorが0だと後手勝ち
        // 非0だと先手

        // A_0 xor A_1 がotherになるようにする

        // and はこれになる
        long and = (A[0] + A[1] - other);
        if (and % 2 != 0)
        {
            Console.WriteLine("-1");
            return;
        }

        and /= 2;

        if (and > A[0])
        {
            Console.WriteLine("-1");
            return;
        }

        // A_0を超えないかつ最大
        long f = A[0] + A[1] - and * 2;

        if ((f & and) > 0)
        {
            Console.WriteLine("-1");
            return;
        }

        long tmp = and;
        for (int i = 50; i >= 0; i--)
        {
            if ((f & (1L << i)) == 0) continue;
            if ((tmp | (1L << i)) > A[0]) continue;
            tmp |= (1L << i);
        }

        if (tmp == 0)
        {
            Console.WriteLine("-1");
            return;
        }

        long ans = A[0] - tmp;
        long ans2 = A[0] + A[1] - tmp;


        if ((tmp ^ ans2) != other)
        {
            Console.WriteLine("-1");
            return;
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

int main(){
    int t,d,s;
    cin>>t>>d>>s;
    if(t<=d*s)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <utility>
using namespace std;

typedef long long lint;
typedef pair<int,int> P;
typedef pair<lint,P> star;


struct SegTree
{
    int N;
    vector<int> Seg;
    void init(int n)
    {
        N = 1;
        while (N < n)N *= 2;
        for (int i = 0; i < N * 2; i++)
        {
            Seg.push_back(INT_MAX);
        }
 
    }
 
    void update(int k, int a)
    {
        k = k - 1 + N;
        Seg[k] = a;
        while (k > 0)
        {
            k = (k - 1) / 2;
            Seg[k] = min(Seg[2 * k + 1], Seg[2 * k + 2]);
        }
    }
    int find_min(int a, int b)
    {
        return query(a, b, 0, 0, N);
    }
 
    int query(int a, int b, int k, int l, int r)
    {
        if (r <= a || l >= b)return INT_MAX;
        if (l >= a&&r <= b)
        {
            return Seg[k];
        }
        else
        {
            return min(query(a, b, k * 2 + 1, l, (r + l) / 2),
                query(a, b, k * 2 + 2, (r + l) / 2, r));
        }
    }
};

SegTree tree[4];
vector<star> stars;
vector<lint> B;
int main()
{
	int N;
	lint d;
	cin>>N>>d;
	for(int i=0;i<4;i++)
		tree[i].init(N);
	
	for(int i=0;i<N;i++)
	{
		P p;
		lint b;
		cin>>p.first>>p.second>>b;
		stars.push_back(star(b,p));
		B.push_back(b);
	}
	sort(stars.begin(),stars.end());
	sort(B.begin(),B.end());
	
	for(int i=0;i<N;i++)
	{
		P p=stars[i].second;
		
		tree[0].update(i,p.first);
		tree[2].update(i,-p.first);
		
		tree[1].update(i,p.second);
		tree[3].update(i,-p.second);
	}
	lint ans=0;
	for(auto it = B.begin();;)
	{
		auto E = upper_bound(B.begin(),B.end(),(lint)*it+d);
		int x=it-B.begin();
		int y=E-B.begin();
		it=upper_bound(B.begin(),B.end(),(lint)*it);
		lint tans=(lint)(-tree[2].find_min(x,y)-tree[0].find_min(x,y))*(lint)(-tree[3].find_min(x,y)-tree[1].find_min(x,y));
		ans=max(ans,tans);
		if(E==B.end())break;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 17964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M;cin>>N;
        
        if(N==0) return 0;
        
        map<pair<int,int>,int> MA;
        
        for(int i=0;i<N;i++){
            int a,b;cin>>a>>b;
            MA[{a,b}]++;
        }
        
        cin>>M;
        int xnow=10,ynow=10;
        
        while(M--){
            char a;int b;cin>>a>>b;
            if(a=='N'){
                while(b--){
                    ynow++;
                    if(MA[{xnow,ynow}]==1) MA[{xnow,ynow}]--;
                }
            }
            if(a=='E'){
                while(b--){
                    xnow++;
                    if(MA[{xnow,ynow}]==1) MA[{xnow,ynow}]--;
                }
            }
            if(a=='S'){
                while(b--){
                    ynow--;
                    if(MA[{xnow,ynow}]==1) MA[{xnow,ynow}]--;
                }
            }
            if(a=='W'){
                while(b--){
                    xnow--;
                    if(MA[{xnow,ynow}]==1) MA[{xnow,ynow}]--;
                }
            }
        }
        
        int sum=0;
        
        for(auto it=MA.begin();it!=MA.end();it++) sum+=(*it).second;
        
        if(sum==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
ll bigp = 1000000007;

int main()
{
    ll n,m,l;
    cin >> n >> m >> l;
    vector<ll> a(m),b(m),c(m);
    rep(i,m){
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<ll>> dist(n,vector<ll>(n));

    // Floyd-Warshall の初期化: dist[i][i] = 0 に注意
    for (ll i = 0; i < n; ++i) {
        for (ll j = 0; j < n; ++j) dist[i][j] = INF;
        dist[i][i] = 0;
    }

    //入力
    rep(i,m){
        dist[a[i]-1][b[i]-1] = c[i];
        dist[b[i]-1][a[i]-1] = c[i];
    }

    //フロイドワーシャル
    for (ll k = 0; k < n; ++k)
        for (ll i = 0; i < n; ++i)
            for (ll j = 0; j < n; ++j)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    vector<vector<ll>> dist_final(n,vector<ll>(n));
    // Floyd-Warshall の初期化: dist[i][i] = 0 に注意
    for (ll i = 0; i < n; ++i) {
        for (ll j = 0; j < n; ++j) dist_final[i][j] = INF;
        dist_final[i][i] = 0;
    }

    //L以下グラフの構成
    rep(i,n){
        reps(j,i+1,n){
            if(dist[i][j]<=l){
                dist_final[i][j] = 1;
                dist_final[j][i] = 1;
            }
        }
    }

    //フロイドワーシャル
    for (ll k = 0; k < n; ++k)
        for (ll i = 0; i < n; ++i)
            for (ll j = 0; j < n; ++j)
                dist_final[i][j] = min(dist_final[i][j], dist_final[i][k] + dist_final[k][j]);


    ll q;
    cin >> q;
    vector<ll> ans;
    rep(i,q){
        ll s,t;
        cin >> s >> t;
        if(dist_final[s-1][t-1]==INF){
            ans.pb(-1);
        }else{
            ans.pb(dist_final[s-1][t-1]-1);
        }
    }
    rep(i,q){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n; cin >> n;
    vector<ll>  x(n), y(n);
    for (ll i = 0; i < n; i++) {
        cin >> x[i];
        y[i] = x[i];
    }
    ll m = n / 2;
    sort(y.begin(), y.end());
    for (ll i = 0; i < n; i++) {
        if (x[i] < y[m]) cout << y[m] << endl;
        else cout << y[m-1] << endl;
    }
}

Measured memory_bytes: 5376
import java.awt.*;
import java.util.*;
import java.util.List;

/**
 * q
 * Created by khrom on 2017/06/15.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Point> rectList = new ArrayList<>();

        int h;
        int w;
        while (true) {
            h = scanner.nextInt();
            w = scanner.nextInt();
            if (h == 0 && w == 0)
                break;
            rectList.add(new Point(w, h));
        }

        for (Point point : rectList) {
            for (int i = 0; i < point.getY(); i++) {
                for (int j = 0; j < point.getX(); j++) {
                    System.out.print("#");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 37888
#include<stdio.h>
#include<math.h>
#define N 1000

int main(void){
  int i,num;
  double x=0.0,y=0.0,px,py;
  double sin(double x);
  double cos(double x);
  double d[N],a[N];  /*distance,angle*/
  double prea;
  int ansX,ansY;
  char hoge;

  for(i=0;;i++){
    scanf("%lf%c%lf",&d[i],&hoge,&a[i]);
    if(a[i]==0) break;
  }
  num=i;
  y+=d[0];
  for(i=0;i<num;i++){
    prea-=a[i];
    px=d[i+1]*cos((prea+90.0)*3.141592/180.0);
    py=d[i+1]*sin((prea+90.0)*3.141592/180.0);
    x+=px;
    y+=py;
  }
  ansX=(int)x;
  ansY=(int)y;
  printf("%d\n%d\n",ansX,ansY);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main() {
  string s; cin >> s;
  if (s.at(5)=='1') cout << "TBD" << endl;
  else{
    if (s.at(6)=='0') cout << "Heisei" << endl;
    else if (s.at(6)=='1') cout << "Heisei" << endl;
    else if (s.at(6)=='2') cout << "Heisei" << endl;
    else if (s.at(6)=='3') cout << "Heisei" << endl;
    else if (s.at(6)=='4') cout << "Heisei" << endl;
    else cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
# bisect_left(a,x):a[i]>=xとなるような最小のi.
# 昇順ソートされたリストaに昇順を崩さずxを挿入できる位置s(0-index)を返す.
# a=[1,3,5,7,9,11,13,15,17,19]
#s = bisect_left(a,4)
# s=2
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, n):
    a[i] += a[i - 1]
a = [0] + a
for i in range(1, m):
    b[i] += b[i - 1]
ans = 0
for i in range(n + 1):
    if a[i] > k:
        break
    x = bisect_right(b, k - a[i])
    ans = max(x + i, ans)
print(ans)


Measured memory_bytes: 111112